You are here

public function PanelsEverywherePageDisplayVariantSubscriber::onSelectPageDisplayVariant in Panels Everywhere 8

Same name and namespace in other branches
  1. 8.4 src/EventSubscriber/PanelsEverywherePageDisplayVariantSubscriber.php \Drupal\panels_everywhere\EventSubscriber\PanelsEverywherePageDisplayVariantSubscriber::onSelectPageDisplayVariant()

Selects the page display variant.

Parameters

\Drupal\Core\Render\PageDisplayVariantSelectionEvent $event: The event to process.

File

src/EventSubscriber/PanelsEverywherePageDisplayVariantSubscriber.php, line 44

Class

PanelsEverywherePageDisplayVariantSubscriber
Selects the appropriate page display variant from 'site_template'.

Namespace

Drupal\panels_everywhere\EventSubscriber

Code

public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {
  $page = $this->entityStorage
    ->load('site_template');
  $route_options = $event
    ->getRouteMatch()
    ->getRouteObject()
    ->getOptions();
  $isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
  if (!is_object($page) || !$page
    ->get('status') || $isAdminRoute) {
    return;
  }
  foreach ($page
    ->getVariants() as $variant) {
    $access = $this
      ->resolveConditions($variant
      ->getSelectionConditions(), $variant
      ->getSelectionLogic());
    if (!$access) {
      continue;
    }
    $plugin = $variant
      ->getVariantPlugin();

    //      kpr($variant->access());
    //      if ($variant->access()) {
    $event
      ->setPluginId($plugin
      ->getPluginId());
    $event
      ->setPluginConfiguration($plugin
      ->getConfiguration());
    $event
      ->setContexts($variant
      ->getContexts());

    //      }
    break;
  }
}