function FormAjaxSubscriber::onView

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::onView()
  2. 10 core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::onView()
  3. 11.x core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::onView()

Alters the wrapper format if this is an AJAX form request.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event: The event to process.

File

core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php, line 63

Class

FormAjaxSubscriber
Wraps AJAX form submissions that are triggered via an exception.

Namespace

Drupal\Core\Form\EventSubscriber

Code

public function onView(GetResponseForControllerResultEvent $event) {
    // To support an AJAX form submission of a form within a block, make the
    // later VIEW subscribers process the controller result as though for
    // HTML display (i.e., add blocks). During that block building, when the
    // submitted form gets processed, an exception gets thrown by
    // \Drupal\Core\Form\FormBuilderInterface::buildForm(), allowing
    // self::onException() to return an AJAX response instead of an HTML one.
    $request = $event->getRequest();
    if ($request->query
        ->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
        $request->query
            ->set(MainContentViewSubscriber::WRAPPER_FORMAT, 'html');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.