Newer
Older
Alex Pott
committed
<?php
/**
* @file
* Definition of Drupal\Core\EventSubscriber\ContentFormControllerSubscriber.
Alex Pott
committed
*/
namespace Drupal\Core\EventSubscriber;
Alex Pott
committed
use Drupal\Core\Controller\HtmlFormController;
use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Alex Pott
committed
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
Alex Pott
committed
/**
* Subscriber for setting wrapping form logic.
Alex Pott
committed
*/
Alex Pott
committed
class ContentFormControllerSubscriber implements EventSubscriberInterface, ContainerAwareInterface {
Alex Pott
committed
Alex Pott
committed
use ContainerAwareTrait;
/**
* The controller resolver.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface
*/
protected $resolver;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
Alex Pott
committed
/**
* Constructs a new ContentFormControllerSubscriber object.
Alex Pott
committed
*
* @param \Drupal\Core\Controller\ControllerResolverInterface $resolver
* The controller resolver.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
Alex Pott
committed
*/
Alex Pott
committed
public function __construct(ControllerResolverInterface $resolver, FormBuilderInterface $form_builder) {
$this->resolver = $resolver;
$this->formBuilder = $form_builder;
Alex Pott
committed
}
/**
* Sets the _controllere on a request based on the request format.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event to process.
Alex Pott
committed
*/
public function onRequestDeriveFormWrapper(GetResponseEvent $event) {
$request = $event->getRequest();
if ($form = $request->attributes->get('_form')) {
$wrapper = new HtmlFormController($this->resolver, $this->container, $form, $this->formBuilder);
$request->attributes->set('_content', array($wrapper, 'getContentResult'));
Alex Pott
committed
}
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onRequestDeriveFormWrapper', 29);
return $events;
}