class AjaxResponseSubscriber in Layout Builder Modal 8
Provides an event subscriber that alters Ajax Responses.
Hierarchy
- class \Drupal\layout_builder_modal\EventSubscriber\AjaxResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of AjaxResponseSubscriber
1 string reference to 'AjaxResponseSubscriber'
1 service uses AjaxResponseSubscriber
File
- src/
EventSubscriber/ AjaxResponseSubscriber.php, line 14
Namespace
Drupal\layout_builder_modal\EventSubscriberView source
class AjaxResponseSubscriber implements EventSubscriberInterface {
/**
* Close modal dialog if Layout Builder is re-rendered.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event.
*/
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
if ($response instanceof AjaxResponse) {
$should_close_dialog = FALSE;
$commands =& $response
->getCommands();
foreach ($commands as $command) {
if (isset($command['selector']) && $command['selector'] === '#layout-builder') {
$should_close_dialog = TRUE;
break;
}
}
if ($should_close_dialog) {
$response
->addCommand(new CloseDialogCommand('#layout-builder-modal'));
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::RESPONSE => [
[
'onResponse',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxResponseSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
AjaxResponseSubscriber:: |
public | function | Close modal dialog if Layout Builder is re-rendered. |