. */ namespace SP\Modules\Web\Controllers\CustomField; use Exception; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Traits\JsonTrait; /** * Class SaveCreateController */ final class SaveCreateController extends CustomFieldSaveBase { use JsonTrait; /** * @return bool * @throws \JsonException */ public function saveCreateAction(): bool { try { if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_CREATE)) { return $this->returnJsonResponse( JsonResponse::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(ActionsInterface::CUSTOMFIELD_CREATE); $itemData = $this->form->getItemData(); $this->customFieldDefService->create($itemData); $this->eventDispatcher->notify( 'create.customField', new Event( $this, EventMessage::factory() ->addDescription(__u('Field added')) ->addDetail(__u('Field'), $itemData->getName()) ) ); return $this->returnJsonResponse( JsonResponse::JSON_SUCCESS, __u('Field added') ); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }