class RouteSubscriber in Lightning Core 8.3
Same name and namespace in other branches
- 8.5 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber
- 8 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber
- 8.2 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber
- 8.4 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber
Dynamically alters various routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\lightning_core\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 16
Namespace
Drupal\lightning_core\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* RouteSubscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $id => $entity_type) {
if ($entity_type
->get('field_ui_base_route') == NULL) {
continue;
}
// The 'Manage fields' page.
$this
->setBundleAsTitle("entity.{$id}.field_ui_fields", $collection);
// The default view display under 'Manage display'.
$this
->setBundleAsTitle("entity.entity_view_display.{$id}.default", $collection);
// A customized view display under 'Manage display'.
$this
->setBundleAsTitle("entity.entity_view_display.{$id}.view_mode", $collection);
// The default form display under 'Manage display'.
$this
->setBundleAsTitle("entity.entity_form_display.{$id}.default", $collection);
// A customized form display under 'Manage display'.
$this
->setBundleAsTitle("entity.entity_form_display.{$id}.form_mode", $collection);
}
}
/**
* Checks if we are currently viewing an entity at its canonical route.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param \Drupal\Core\Routing\RouteMatchInterface|NULL $route_match
* (optional) The current route match.
*
* @return bool
* TRUE if we are at the entity's canonical route, FALSE otherwise.
*/
public static function isViewing(EntityInterface $entity, RouteMatchInterface $route_match = NULL) {
$route_match = $route_match ?: \Drupal::routeMatch();
$entity_type = $entity
->getEntityTypeId();
return $route_match
->getRouteName() == "entity.{$entity_type}.canonical" && $route_match
->getRawParameter($entity_type) == $entity
->id();
}
/**
* Sets FieldUiTitleController::bundle() as the title callback for a route.
*
* @param string $route_name
* The route name.
* @param \Symfony\Component\Routing\RouteCollection $collection
* The complete route collection containing the route to alter.
*/
protected function setBundleAsTitle($route_name, RouteCollection $collection) {
$route = $collection
->get($route_name);
if ($route) {
$route
->setDefault('_title_callback', FieldUiTitleController::class . '::bundle');
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// We need to run after Field UI.
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-110,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The entity type manager service. | |
RouteSubscriber:: |
public | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public static | function | Checks if we are currently viewing an entity at its canonical route. | |
RouteSubscriber:: |
protected | function | Sets FieldUiTitleController::bundle() as the title callback for a route. | |
RouteSubscriber:: |
public | function | RouteSubscriber constructor. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |