You are here

class RouteSubscriber in Translation Management Tool 8

Listens to the dynamic route events.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

translators/tmgmt_local/src/Routing/RouteSubscriber.php, line 12

Namespace

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

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

  /**
   * Constructs a new RouteSubscriber.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($collection
      ->get('tmgmt.admin_tmgmt')) {
      $route = $collection
        ->get('tmgmt.admin_tmgmt');
      $route
        ->addRequirements([
        '_permission' => $collection
          ->get('tmgmt.admin_tmgmt')
          ->getRequirement('_permission') . '+administer translation tasks+provide translation services',
      ]);
    }
    foreach ($collection
      ->all() as $route) {
      if (strpos($route
        ->getPath(), '/translate') === 0 && $this->configFactory
        ->get('tmgmt_local.settings')
        ->get('use_admin_theme') || strpos($route
        ->getPath(), '/manage-translate') === 0) {
        $route
          ->setOption('_admin_route', TRUE);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$configFactory protected property The config factory.
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::__construct public function Constructs a new RouteSubscriber.
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