You are here

class ContentHubViewSubscriber in Acquia Content Hub 8

View subscriber rendering main content render arrays into responses.

Additional target rendering formats can be defined by adding another service that implements \Drupal\Core\Render\MainContent\MainContentRendererInterface and tagging it as a

render . main_content_renderer;

, then \Drupal\Core\Render\MainContent\MainContentRenderersPass will detect it and use it when appropriate.

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\ContentHubViewSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ContentHubViewSubscriber

See also

\Drupal\Core\Render\MainContent\MainContentRendererInterface

\Drupal\Core\Render\MainContentControllerPass

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

File

src/EventSubscriber/ContentHubViewSubscriber.php, line 27

Namespace

Drupal\acquia_contenthub\EventSubscriber
View source
class ContentHubViewSubscriber implements EventSubscriberInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The account switcher service.
   *
   * @var \Drupal\Core\Session\AccountSwitcherInterface
   */
  protected $accountSwitcher;

  /**
   * The render user session.
   *
   * @var \Drupal\acquia_contenthub\Session\ContentHubUserSession
   */
  protected $renderAccount;

  /**
   * Logger.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerFactory;

  /**
   * ContentHubViewSubscriber constructor.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Session\AccountSwitcherInterface $account_switcher
   *   The Account Switcher Service.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
   *   The logger factory.
   */
  public function __construct(RouteMatchInterface $route_match, ConfigFactoryInterface $config_factory, AccountSwitcherInterface $account_switcher, LoggerChannelFactoryInterface $logger_factory) {
    $this->routeMatch = $route_match;
    $this->configFactory = $config_factory;
    $this->accountSwitcher = $account_switcher;
    $this->renderAccount = new ContentHubUserSession($this->configFactory
      ->get('acquia_contenthub.entity_config')
      ->get('user_role'));
    $this->loggerFactory = $logger_factory;
  }

  /**
   * Switch to the render Content Hub user.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
   *   The filter controller event.
   */
  public function onKernelController(FilterControllerEvent $event) {
    if ($this->routeMatch
      ->getRouteName() === 'acquia_contenthub.content_entity_display.entity') {
      $this->accountSwitcher
        ->switchTo($this->renderAccount);
    }
  }

  /**
   * Switch back from the render Content Hub user.
   *
   * @param \Symfony\Component\HttpKernel\Event\FinishRequestEvent $event
   *   The finish request event.
   */
  public function onKernelFinishRequest(FinishRequestEvent $event) {
    if ($this->routeMatch
      ->getRouteName() === 'acquia_contenthub.content_entity_display.entity') {
      $this->accountSwitcher
        ->switchBack();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::CONTROLLER => [
        'onKernelController',
      ],
      KernelEvents::FINISH_REQUEST => [
        'onKernelFinishRequest',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentHubViewSubscriber::$accountSwitcher protected property The account switcher service.
ContentHubViewSubscriber::$configFactory protected property The config factory.
ContentHubViewSubscriber::$loggerFactory protected property Logger.
ContentHubViewSubscriber::$renderAccount protected property The render user session.
ContentHubViewSubscriber::$routeMatch protected property The current route match.
ContentHubViewSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ContentHubViewSubscriber::onKernelController public function Switch to the render Content Hub user.
ContentHubViewSubscriber::onKernelFinishRequest public function Switch back from the render Content Hub user.
ContentHubViewSubscriber::__construct public function ContentHubViewSubscriber constructor.