. */ namespace SP\Modules\Web\Controllers\ItemPreset; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ValidationException; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; /** * Class SaveCreateController */ final class SaveCreateController extends ItemPresetSaveBase { use JsonTrait; /** * @return bool * @throws JsonException */ public function saveCreateAction(): bool { try { if (!$this->acl->checkUserAccess(AclActionsInterface::ITEMPRESET_CREATE)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(AclActionsInterface::ITEMPRESET_CREATE); $itemData = $this->form->getItemData(); $id = $this->itemPresetService->create($itemData); $this->eventDispatcher->notify( 'create.itemPreset', new Event( $this, EventMessage::factory() ->addDescription(__u('Value created')) ->addDetail(__u('Type'), $itemData->getItemPresetData()->getType()) ->addDetail(__u('ID'), $id) ) ); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Value created')); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }