class PanelsEverywherePageDisplayVariantSubscriber in Panels Everywhere 8
Same name and namespace in other branches
- 8.4 src/EventSubscriber/PanelsEverywherePageDisplayVariantSubscriber.php \Drupal\panels_everywhere\EventSubscriber\PanelsEverywherePageDisplayVariantSubscriber
Selects the appropriate page display variant from 'site_template'.
Hierarchy
- class \Drupal\panels_everywhere\EventSubscriber\PanelsEverywherePageDisplayVariantSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses ConditionAccessResolverTrait
Expanded class hierarchy of PanelsEverywherePageDisplayVariantSubscriber
1 string reference to 'PanelsEverywherePageDisplayVariantSubscriber'
1 service uses PanelsEverywherePageDisplayVariantSubscriber
File
- src/
EventSubscriber/ PanelsEverywherePageDisplayVariantSubscriber.php, line 17
Namespace
Drupal\panels_everywhere\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionAccessResolverTrait:: |
protected | function | Resolves the given conditions based on the condition logic ('and'/'or'). | |
PanelsEverywherePageDisplayVariantSubscriber:: |
protected | property | The entity storage. | |
PanelsEverywherePageDisplayVariantSubscriber:: |
static | function | Returns an array of event names this subscriber wants to listen to. | |
PanelsEverywherePageDisplayVariantSubscriber:: |
public | function | Selects the page display variant. | |
PanelsEverywherePageDisplayVariantSubscriber:: |
public | function | Constructs a new PageManagerRoutes. |