class DefaultRouteSubscriber in Form mode manager 8
Subscriber for form_mode_manager routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\form_mode_manager\Routing\EventSubscriber\DefaultRouteSubscriber
Expanded class hierarchy of DefaultRouteSubscriber
1 string reference to 'DefaultRouteSubscriber'
1 service uses DefaultRouteSubscriber
File
- src/
Routing/ EventSubscriber/ DefaultRouteSubscriber.php, line 15
Namespace
Drupal\form_mode_manager\Routing\EventSubscriberView source
class DefaultRouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity display repository.
*
* @var \Drupal\form_mode_manager\FormModeManagerInterface
*/
protected $formModeManager;
/**
* The Routes Manager Plugin.
*
* @var \Drupal\form_mode_manager\EntityRoutingMapManager
*/
protected $entityRoutingMap;
/**
* Constructs a new RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity type manager.
* @param \Drupal\form_mode_manager\FormModeManagerInterface $form_mode_manager
* The form mode manager.
* @param \Drupal\form_mode_manager\EntityRoutingMapManager $plugin_routes_manager
* Plugin EntityRoutingMap to retrieve entity form operation routes.
*/
public function __construct(EntityTypeManagerInterface $entity_manager, FormModeManagerInterface $form_mode_manager, EntityRoutingMapManager $plugin_routes_manager) {
$this->entityTypeManager = $entity_manager;
$this->formModeManager = $form_mode_manager;
$this->entityRoutingMap = $plugin_routes_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
$form_modes_definitions = $this->formModeManager
->getAllFormModesDefinitions();
foreach (array_keys($form_modes_definitions) as $entity_type_id) {
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
$this
->enhanceDefaultRoutes($collection, $entity_type
->id());
}
}
/**
* Enhance existing entity operation routes (add_page, add_form, edit_form).
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection to retrieve parent entity routes.
* @param string $entity_type_id
* The ID of the entity type.
*/
protected function enhanceDefaultRoutes(RouteCollection $collection, $entity_type_id) {
$this
->enhanceDefaultAddPageRoutes($collection, $entity_type_id);
$this
->enhanceDefaultAddRoutes($collection, $entity_type_id);
$this
->enhanceDefaultEditRoutes($collection, $entity_type_id);
}
/**
* Enhance entity operation routes add_page.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection to retrieve parent entity routes.
* @param string $entity_type_id
* The ID of the entity type.
*/
protected function enhanceDefaultAddPageRoutes(RouteCollection $collection, $entity_type_id) {
$entity_add_page = $this->entityRoutingMap
->createInstance($entity_type_id, [
'entityTypeId' => $entity_type_id,
])
->getOperation('add_page');
if ($entity_add_page && ($route = $collection
->get($entity_add_page))) {
$collection
->add($entity_add_page, $this
->routeEnhancer($route, $entity_type_id));
}
}
/**
* Enhance entity operation routes add.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection to retrieve parent entity routes.
* @param string $entity_type_id
* The ID of the entity type.
*/
protected function enhanceDefaultAddRoutes(RouteCollection $collection, $entity_type_id) {
$entity_route_name = $this->entityRoutingMap
->createInstance($entity_type_id, [
'entityTypeId' => $entity_type_id,
])
->getOperation('add_form');
if ($route = $collection
->get($entity_route_name)) {
$collection
->add($entity_route_name, $this
->routeEnhancer($route, $entity_type_id));
}
}
/**
* Enhance entity operation routes edit.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection to retrieve parent entity routes.
* @param string $entity_type_id
* The ID of the entity type.
*/
protected function enhanceDefaultEditRoutes(RouteCollection $collection, $entity_type_id) {
$entity_route_name = $this->entityRoutingMap
->createInstance($entity_type_id, [
'entityTypeId' => $entity_type_id,
])
->getOperation('edit_form');
if ($route = $collection
->get($entity_route_name)) {
$collection
->add($entity_route_name, $this
->routeEnhancer($route, $entity_type_id));
}
}
/**
* Add required parameters on route basis.
*
* @param \Symfony\Component\Routing\Route $route
* The route object of entity.
* @param string $entity_type_id
* The ID of the entity type.
*
* @return \Symfony\Component\Routing\Route
* The route enhanced.
*/
public function routeEnhancer(Route $route, $entity_type_id) {
$route
->setRequirement('_permission', "use {$entity_type_id}.default form mode");
return $route;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultRouteSubscriber:: |
protected | property | The Routes Manager Plugin. | |
DefaultRouteSubscriber:: |
protected | property | The entity type manager service. | |
DefaultRouteSubscriber:: |
protected | property | The entity display repository. | |
DefaultRouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
DefaultRouteSubscriber:: |
protected | function | Enhance entity operation routes add_page. | |
DefaultRouteSubscriber:: |
protected | function | Enhance entity operation routes add. | |
DefaultRouteSubscriber:: |
protected | function | Enhance entity operation routes edit. | |
DefaultRouteSubscriber:: |
protected | function | Enhance existing entity operation routes (add_page, add_form, edit_form). | |
DefaultRouteSubscriber:: |
public | function | Add required parameters on route basis. | |
DefaultRouteSubscriber:: |
public | function | Constructs a new RouteSubscriber object. | |
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 |