You are here

class PanelsEverywherePageDisplayVariantSubscriber in Panels Everywhere 8

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

Selects the appropriate page display variant from 'site_template'.

Hierarchy

Expanded class hierarchy of PanelsEverywherePageDisplayVariantSubscriber

1 string reference to 'PanelsEverywherePageDisplayVariantSubscriber'
panels_everywhere.services.yml in ./panels_everywhere.services.yml
panels_everywhere.services.yml
1 service uses PanelsEverywherePageDisplayVariantSubscriber
panels_everywhere.page_display_variant_subscriber in ./panels_everywhere.services.yml
Drupal\panels_everywhere\EventSubscriber\PanelsEverywherePageDisplayVariantSubscriber

File

src/EventSubscriber/PanelsEverywherePageDisplayVariantSubscriber.php, line 17

Namespace

Drupal\panels_everywhere\EventSubscriber
View source
class PanelsEverywherePageDisplayVariantSubscriber implements EventSubscriberInterface {
  use ConditionAccessResolverTrait;

  /**
   * The entity storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $entityStorage;

  /**
   * Constructs a new PageManagerRoutes.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityStorage = $entity_manager
      ->getStorage('page');
  }

  /**
   * Selects the page display variant.
   *
   * @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
   *   The event to process.
   */
  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;
    }
  }

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = array(
      'onSelectPageDisplayVariant',
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConditionAccessResolverTrait::resolveConditions protected function Resolves the given conditions based on the condition logic ('and'/'or').
PanelsEverywherePageDisplayVariantSubscriber::$entityStorage protected property The entity storage.
PanelsEverywherePageDisplayVariantSubscriber::getSubscribedEvents static function Returns an array of event names this subscriber wants to listen to.
PanelsEverywherePageDisplayVariantSubscriber::onSelectPageDisplayVariant public function Selects the page display variant.
PanelsEverywherePageDisplayVariantSubscriber::__construct public function Constructs a new PageManagerRoutes.