You are here

class ContentHubPageDisplayVariantSubscriber in Acquia Content Hub 8

Selects the simple page display variant.

Hierarchy

Expanded class hierarchy of ContentHubPageDisplayVariantSubscriber

See also

\Drupal\Core\Render\Plugin\DisplayVariant\SimplePageVariant

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

File

src/EventSubscriber/ContentHubPageDisplayVariantSubscriber.php, line 15

Namespace

Drupal\acquia_contenthub\EventSubscriber
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentHubPageDisplayVariantSubscriber::$routeMatch protected property The current route match.
ContentHubPageDisplayVariantSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ContentHubPageDisplayVariantSubscriber::onSelectPageDisplayVariant public function Selects the block page display variant.
ContentHubPageDisplayVariantSubscriber::__construct public function ContentHubViewSubscriber constructor.