class RouteSubscriber in Entity Extra Field 8
Same name and namespace in other branches
- 2.0.x modules/entity_extra_field_ui/src/Routing/RouteSubscriber.php \Drupal\entity_extra_field_ui\Routing\RouteSubscriber
Define the route subscriber.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\entity_extra_field_ui\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
- entity_extra_field_ui.services.yml in modules/
entity_extra_field_ui/ entity_extra_field_ui.services.yml - modules/entity_extra_field_ui/entity_extra_field_ui.services.yml
1 service uses RouteSubscriber
- entity_exta_field_ui.route_subscriber in modules/
entity_extra_field_ui/ entity_extra_field_ui.services.yml - Drupal\entity_extra_field_ui\Routing\RouteSubscriber
File
- modules/
entity_extra_field_ui/ src/ Routing/ RouteSubscriber.php, line 13
Namespace
Drupal\entity_extra_field_ui\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Route subscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Alters existing routes for a specific collection.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection for adding routes.
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $definition) {
$base_route_name = $definition
->get('field_ui_base_route');
if (!isset($base_route_name)) {
continue;
}
$entity_route = $collection
->get($base_route_name);
if (!isset($entity_route)) {
continue;
}
$entity_path = $entity_route
->getPath();
$entity_options = $entity_route
->getOptions();
$entity_bundle_type = $definition
->getBundleEntityType();
if (isset($entity_bundle_type)) {
$entity_options['parameters'][$entity_bundle_type] = [
'type' => 'entity:' . $entity_bundle_type,
];
}
$route = new Route("{$entity_path}/extra-fields");
$route
->setDefaults([
'_title' => 'Manage extra fields',
'_entity_list' => 'entity_extra_field',
'entity_type_id' => $entity_type_id,
])
->setRequirements([
'_permission' => 'administer entity extra field',
])
->setOptions($entity_options);
$collection
->add("entity.{$entity_type_id}.extra_fields", $route);
$route = new Route("{$entity_path}/extra-fields/add");
$route
->setDefaults([
'_title' => 'Add extra field',
'_entity_form' => 'entity_extra_field.add',
'entity_type_id' => $entity_type_id,
])
->setRequirements([
'_permission' => 'administer entity extra field',
])
->setOptions($entity_options);
$collection
->add("entity.{$entity_type_id}.extra_fields.add", $route);
$route = new Route("{$entity_path}/extra-fields/{entity_extra_field}/edit");
$route
->setDefaults([
'_title' => 'Edit extra field',
'_entity_form' => 'entity_extra_field.edit',
'entity_type_id' => $entity_type_id,
])
->setRequirements([
'_permission' => 'administer entity extra field',
])
->setOptions($entity_options);
$collection
->add("entity.{$entity_type_id}.extra_fields.edit", $route);
$route = new Route("{$entity_path}/extra-fields/{entity_extra_field}/delete");
$route
->setDefaults([
'_title' => 'Delete extra field',
'_entity_form' => 'entity_extra_field.delete',
'entity_type_id' => $entity_type_id,
])
->setRequirements([
'_permission' => 'administer entity extra field',
])
->setOptions($entity_options);
$collection
->add("entity.{$entity_type_id}.extra_fields.delete", $route);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | ||
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | Route subscriber 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 |