final class RouteSubscriber in CiviCRM Entity 8.3
Alters generated routes for CiviCRM Entity entity definitions.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\civicrm_entity\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 14
Namespace
Drupal\civicrm_entity\RoutingView source
final class RouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* RouteSubscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Only run if Field UI is installed.
if (!$this->moduleHandler
->moduleExists('field_ui')) {
return;
}
$has_layout_builder = $this->moduleHandler
->moduleExists('layout_builder');
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if (!$entity_type
->get('civicrm_entity_ui_exposed')) {
continue;
}
if (!$entity_type
->hasKey('bundle')) {
continue;
}
$field_ui_routes = [
"entity.{$entity_type_id}.field_ui_fields" => [
'bundle' => $entity_type_id,
],
"entity.field_config.{$entity_type_id}_field_edit_form" => [
'bundle' => $entity_type_id,
],
"entity.field_config.{$entity_type_id}_storage_edit_form" => [
'bundle' => $entity_type_id,
],
"entity.field_config.{$entity_type_id}_field_delete_form" => [
'bundle' => $entity_type_id,
],
"field_ui.field_storage_config_add_{$entity_type_id}" => [
'bundle' => $entity_type_id,
],
"entity.entity_form_display.{$entity_type_id}.default" => [
'bundle' => $entity_type_id,
],
"entity.entity_form_display.{$entity_type_id}.form_mode" => [
'bundle' => $entity_type_id,
],
"entity.entity_view_display.{$entity_type_id}.default" => [
'bundle' => $entity_type_id,
],
"entity.entity_view_display.{$entity_type_id}.view_mode" => [
'bundle' => $entity_type_id,
],
];
if ($has_layout_builder) {
// @todo we should iterate over the section storage definitions.
// that means we'd need to conditionally inject the manage service.
// @see \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage::buildRoutes
$field_ui_routes["layout_builder.defaults.{$entity_type_id}.view"] = [
'bundle' => $entity_type_id,
];
// @see \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::buildRoutes
$field_ui_routes["layout_builder.overrides.{$entity_type_id}.view"] = [
'bundle' => $entity_type_id,
];
$field_ui_routes["layout_builder.defaults.{$entity_type_id}.discard_changes"] = [
'bundle' => $entity_type_id,
];
$field_ui_routes["layout_builder.defaults.{$entity_type_id}.disable"] = [
'bundle' => $entity_type_id,
];
}
foreach ($field_ui_routes as $route_name => $defaults) {
$route = $collection
->get($route_name);
assert($route !== NULL);
foreach ($defaults as $name => $default) {
$route
->setDefault($name, $default);
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// Field UI's route subscriber runs at -100.
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-200,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
private | property | The entity type manager. | |
RouteSubscriber:: |
protected | property | The module handler. | |
RouteSubscriber:: |
protected | 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 | function | RouteSubscriber constructor. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |