. */ namespace SP\Modules\Web\Controllers\UserProfile; 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; use SP\Mvc\Controller\ItemTrait; /** * Class SaveCreateController */ final class SaveCreateController extends UserProfileSaveBase { use JsonTrait, ItemTrait; /** * @return bool * @throws \JsonException */ public function saveCreateAction(): bool { try { if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_CREATE)) { return $this->returnJsonResponse( JsonResponse::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(ActionsInterface::PROFILE_CREATE); $profileData = $this->form->getItemData(); $id = $this->userProfileService->create($profileData); $this->eventDispatcher->notify( 'create.userProfile', new Event( $this, EventMessage::factory() ->addDescription(__u('Profile added')) ->addDetail(__u('Name'), $profileData->getName()) ) ); $this->addCustomFieldsForItem(ActionsInterface::PROFILE, $id, $this->request, $this->customFieldService); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Profile added')); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }