You are here

public function AjaxResponseSubscriber::onResponse in Layout Builder Modal 8

Close modal dialog if Layout Builder is re-rendered.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event.

File

src/EventSubscriber/AjaxResponseSubscriber.php, line 22

Class

AjaxResponseSubscriber
Provides an event subscriber that alters Ajax Responses.

Namespace

Drupal\layout_builder_modal\EventSubscriber

Code

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'));
    }
  }
}