ContentHubPageDisplayVariantSubscriber.php in Acquia Content Hub 8
Namespace
Drupal\acquia_contenthub\EventSubscriberFile
src/EventSubscriber/ContentHubPageDisplayVariantSubscriber.phpView source
<?php
namespace Drupal\acquia_contenthub\EventSubscriber;
use Drupal\Core\Render\PageDisplayVariantSelectionEvent;
use Drupal\Core\Render\RenderEvents;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Selects the simple page display variant.
*
* @see \Drupal\Core\Render\Plugin\DisplayVariant\SimplePageVariant
*/
class ContentHubPageDisplayVariantSubscriber implements EventSubscriberInterface {
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* ContentHubViewSubscriber constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
}
/**
* Selects the block page display variant.
*
* @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
* The event to process.
*/
public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {
if ($this->routeMatch
->getRouteName() === 'acquia_contenthub.content_entity_display.entity') {
$event
->setPluginId('contenthub_page');
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
'onSelectPageDisplayVariant',
-1,
];
return $events;
}
}
Classes
Name | Description |
---|---|
ContentHubPageDisplayVariantSubscriber | Selects the simple page display variant. |