In an Action, errored forms are propagated via the ActionEvent

This commit is contained in:
franck
2013-07-24 20:08:00 +02:00
parent 94ee77f4f8
commit 182b13ceca
8 changed files with 40 additions and 23 deletions

View File

@@ -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;
}
}

View File

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