In an Action, errored forms are propagated via the ActionEvent
This commit is contained in:
@@ -49,7 +49,7 @@ abstract class ActionEvent extends Event
|
||||
*/
|
||||
protected $action;
|
||||
|
||||
protected $form = null;
|
||||
protected $errorForm = null;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -79,4 +79,18 @@ abstract class ActionEvent extends Event
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public function setErrorForm(BaseForm $form) {
|
||||
$this->errorForm = $form;
|
||||
|
||||
if ($form != null) $this->stopPropagation();
|
||||
}
|
||||
|
||||
public function getErrorForm() {
|
||||
return $this->errorForm;
|
||||
}
|
||||
|
||||
public function hasErrorForm() {
|
||||
return $this->errorForm != null ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||
use Thelia\Core\Factory\ActionEventFactory;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -38,6 +39,14 @@ use Thelia\Core\Factory\ActionEventFactory;
|
||||
*/
|
||||
class ControllerListener implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ParserContext the parser context
|
||||
*/
|
||||
protected $parserContext;
|
||||
|
||||
public function __construct(ParserContext $parserContext) {
|
||||
$this->parserContext = $parserContext;
|
||||
}
|
||||
|
||||
public function onKernelController(FilterControllerEvent $event)
|
||||
{
|
||||
@@ -49,6 +58,11 @@ class ControllerListener implements EventSubscriberInterface
|
||||
$event = new ActionEventFactory($request, $action, $event->getKernel()->getContainer()->getParameter("thelia.actionEvent"));
|
||||
$actionEvent = $event->createActionEvent();
|
||||
$dispatcher->dispatch("action.".$action, $actionEvent);
|
||||
|
||||
// Process form errors
|
||||
if ($actionEvent->hasErrorForm()) {
|
||||
$this->parserContext->setErrorForm($actionEvent->getErrorForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user