Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-28514: It's possible to save section with identifier containing spaces #269

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/bundle/Controller/SectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand All @@ -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());
}
}

Expand All @@ -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);

Expand All @@ -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());
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/lib/Form/Data/Section/SectionCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
17 changes: 15 additions & 2 deletions src/lib/Form/Data/Section/SectionUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

/**
Expand Down