You are here

class RouteSubscriber in Allow a content type only once (Only One) 8

Class RouteSubscriber.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 13

Namespace

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

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

  /**
   * The local action manager instance.
   *
   * @var \Drupal\Core\Menu\LocalActionManager
   */
  protected $localActionManager;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Menu\LocalActionManager $local_action_manager
   *   The local action manager instance.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LocalActionManager $local_action_manager) {
    $this->configFactory = $config_factory;
    $this->localActionManager = $local_action_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {

    // Cleaning the action link cache.
    $this->localActionManager
      ->clearCachedDefinitions();

    // Removing the onlyone.add_page route if is not needed and exists.
    if (!$this->configFactory
      ->get('onlyone.settings')
      ->get('onlyone_new_menu_entry') && $collection
      ->get('onlyone.add_page')) {
      $collection
        ->remove('onlyone.add_page');
    }
  }

}

Members

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