. */ namespace SP\Modules\Web\Controllers\ItemPreset; 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 SaveEditController */ final class SaveEditController extends ItemPresetSaveBase { use JsonTrait; /** * Saves edit action * * @param int $id * * @return bool * @throws \JsonException */ public function saveEditAction(int $id): bool { try { if (!$this->acl->checkUserAccess(ActionsInterface::ITEMPRESET_EDIT)) { return $this->returnJsonResponse( JsonResponse::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(ActionsInterface::ITEMPRESET_EDIT, $id); $itemData = $this->form->getItemData(); $this->itemPresetService->update($itemData); $this->eventDispatcher->notifyEvent( 'edit.itemPreset', new Event( $this, EventMessage::factory() ->addDescription(__u('Value updated')) ->addDetail(__u('Type'), $itemData->getItemPresetData()->getType()) ->addDetail(__u('ID'), $id) ) ); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Value updated')); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notifyEvent('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }