diff --git a/src/bundle/Controller/SectionController.php b/src/bundle/Controller/SectionController.php index d59613e04e..1e9e935868 100644 --- a/src/bundle/Controller/SectionController.php +++ b/src/bundle/Controller/SectionController.php @@ -34,6 +34,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Translation\TranslatorInterface; +use Exception; class SectionController extends Controller { @@ -375,7 +376,8 @@ public function createAction(Request $request): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $result = $this->submitHandler->handle($form, function (SectionCreateData $data) { + $data = $form->getData(); + try { $sectionCreateStruct = $this->sectionCreateMapper->reverseMap($data); $section = $this->sectionService->createSection($sectionCreateStruct); @@ -391,10 +393,8 @@ public function createAction(Request $request): Response return new RedirectResponse($this->generateUrl('ezplatform.section.view', [ 'sectionId' => $section->id, ])); - }); - - if ($result instanceof Response) { - return $result; + } catch (Exception $e) { + $this->notificationHandler->error($e->getMessage()); } } @@ -417,7 +417,8 @@ public function updateAction(Request $request, Section $section): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $result = $this->submitHandler->handle($form, function (SectionUpdateData $data) { + $data = $form->getData(); + try { $sectionUpdateStruct = $this->sectionUpdateMapper->reverseMap($data); $section = $this->sectionService->updateSection($data->getSection(), $sectionUpdateStruct); @@ -433,10 +434,8 @@ public function updateAction(Request $request, Section $section): Response return new RedirectResponse($this->generateUrl('ezplatform.section.view', [ 'sectionId' => $section->id, ])); - }); - - if ($result instanceof Response) { - return $result; + } catch (Exception $e) { + $this->notificationHandler->error($e->getMessage()); } } diff --git a/src/lib/Form/Data/Section/SectionCreateData.php b/src/lib/Form/Data/Section/SectionCreateData.php index 9392097db1..fb52eadb6a 100644 --- a/src/lib/Form/Data/Section/SectionCreateData.php +++ b/src/lib/Form/Data/Section/SectionCreateData.php @@ -8,15 +8,29 @@ namespace EzSystems\EzPlatformAdminUi\Form\Data\Section; +use Symfony\Component\Validator\Constraints as Assert; + /** * @todo add validation */ class SectionCreateData { - /** @var string|null */ + /** + * @var string|null + * + * @Assert\NotBlank() + * @Assert\Regex( + * pattern="/^[[:alnum:]_]+$/", + * message="ez.section.identifier.format" + * ) + */ protected $identifier; - /** @var string|null */ + /** + * @var string|null + * + * @Assert\NotBlank() + */ protected $name; /** diff --git a/src/lib/Form/Data/Section/SectionUpdateData.php b/src/lib/Form/Data/Section/SectionUpdateData.php index 5729514f49..b96b94754f 100644 --- a/src/lib/Form/Data/Section/SectionUpdateData.php +++ b/src/lib/Form/Data/Section/SectionUpdateData.php @@ -9,6 +9,7 @@ namespace EzSystems\EzPlatformAdminUi\Form\Data\Section; use eZ\Publish\API\Repository\Values\Content\Section; +use Symfony\Component\Validator\Constraints as Assert; /** * @todo add validation @@ -18,10 +19,22 @@ class SectionUpdateData /** @var Section|null */ protected $section; - /** @var string|null */ + /** + * @var string|null + * + * @Assert\NotBlank() + * @Assert\Regex( + * pattern="/^[[:alnum:]_]+$/", + * message="ez.section.identifier.format" + * ) + */ protected $identifier; - /** @var string|null */ + /** + * @var string|null + * + * @Assert\NotBlank() + */ protected $name; /**