Skip to content

Commit

Permalink
Merge pull request #269 from mikadamczyk/ezp-28514-it-is-possible-to-…
Browse files Browse the repository at this point in the history
…save-section-with-identifier-containing-spaces

EZP-28514: It's possible to save section with identifier containing spaces
  • Loading branch information
Łukasz Serwatka authored Dec 21, 2017
2 parents 5f6966b + 47b0ccb commit 216eab1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
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

0 comments on commit 216eab1

Please sign in to comment.