You are here

class RouteSubscriber in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Routing/RouteSubscriber.php \Drupal\bibcite_entity\Routing\RouteSubscriber

Listens to the dynamic route events.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
bibcite_entity.services.yml in modules/bibcite_entity/bibcite_entity.services.yml
modules/bibcite_entity/bibcite_entity.services.yml
1 service uses RouteSubscriber
bibcite_entity.route_subscriber in modules/bibcite_entity/bibcite_entity.services.yml
Drupal\bibcite_entity\Routing\RouteSubscriber

File

modules/bibcite_entity/src/Routing/RouteSubscriber.php, line 12

Namespace

Drupal\bibcite_entity\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

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

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * Alters existing routes for a specific collection.
   *
   * @param \Symfony\Component\Routing\RouteCollection $collection
   *   The route collection for adding routes.
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection
      ->get('entity.bibcite_reference.revision')) {
      $route
        ->setDefault('_controller', '\\Drupal\\bibcite_entity\\Controller\\ReferenceViewController::viewRevision');
      $route
        ->setDefault('_title_callback', '\\Drupal\\bibcite_entity\\Controller\\ReferenceViewController::revisionTitle');
    }
    if ($route = $collection
      ->get('entity.bibcite_reference.canonical')) {
      $config = $this->configFactory
        ->get('bibcite_entity.reference.settings');
      $view_mode = $config
        ->get('display_override.reference_page_view_mode');

      // Let's leave it for now for compatibility with default controller.
      // @todo Remove it (and 3 previous lines)?
      $route
        ->setDefault('_entity_view', 'bibcite_reference.' . $view_mode);

      // View mode is cached on the route level when passed as route param.
      // Clearing routes' cache is required in this case to apply
      // "Reference page view mode" setting changes.
      // So, let's move Reference page view mode logic to custom controller
      // instead.
      $route
        ->setDefault('_controller', '\\Drupal\\bibcite_entity\\Controller\\ReferenceViewController::view');
    }
    if ($route = $collection
      ->get('entity.bibcite_reference.version_history')) {
      $route
        ->setOption('_admin_route', TRUE);
    }
    if ($route = $collection
      ->get('entity.bibcite_reference.revision_revert_form')) {
      $route
        ->setOption('_admin_route', TRUE);
    }
    if ($route = $collection
      ->get('bibcite_reference.revision_delete_confirm')) {
      $route
        ->setOption('_admin_route', TRUE);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$configFactory protected property Config factory service.
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::__construct public function
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1