class RouteSubscriber in Allow a content type only once (Only One) 8
Class RouteSubscriber.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\onlyone\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 13
Namespace
Drupal\onlyone\RoutingView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The config factory. | |
RouteSubscriber:: |
protected | property | The local action manager instance. | |
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | Constructor. | |
RouteSubscriberBase:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | 5 |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |