You are here

public function IFrame::propagateSelection in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/EntityBrowser/Display/IFrame.php \Drupal\entity_browser\Plugin\EntityBrowser\Display\IFrame::propagateSelection()

KernelEvents::RESPONSE listener.

Intercepts default response and injects response that will trigger JS to propagate selected entities upstream.

Parameters

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

File

src/Plugin/EntityBrowser/Display/IFrame.php, line 211

Class

IFrame
Presents entity browser in an iFrame.

Namespace

Drupal\entity_browser\Plugin\EntityBrowser\Display

Code

public function propagateSelection(FilterResponseEvent $event) {
  $render = [
    '#attached' => [
      'library' => [
        'entity_browser/' . $this->pluginDefinition['id'] . '_selection',
      ],
      'drupalSettings' => [
        'entity_browser' => [
          $this->pluginDefinition['id'] => [
            'entities' => array_map(function (EntityInterface $item) {
              return [
                $item
                  ->id(),
                $item
                  ->uuid(),
                $item
                  ->getEntityTypeId(),
              ];
            }, $this->entities),
            'uuid' => $this->request->query
              ->get('uuid'),
          ],
        ],
      ],
    ],
  ];
  $event
    ->setResponse($this->bareHtmlPageRenderer
    ->renderBarePage($render, $this
    ->t('Entity browser'), 'page'));
}