class RouteSubscriber in Replicate UI 8
Hierarchy
- class \Drupal\replicate_ui\RouteSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RouteSubscriber
1 file declares its use of RouteSubscriber
- RouteSubscriberTest.php in tests/
src/ Unit/ RouteSubscriberTest.php
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
RouteSubscriber.php, line 13
Namespace
Drupal\replicate_uiView source
class RouteSubscriber implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Creates a new RouteSubscriber instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $config_factory) {
$this->entityTypeManager = $entityTypeManager;
$this->configFactory = $config_factory;
}
public function onRouteBuild(RouteBuildEvent $event) {
$config = $this->configFactory
->get('replicate_ui.settings');
$collection = $event
->getRouteCollection();
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type instanceof ContentEntityTypeInterface && in_array($entity_type_id, (array) $config
->get('entity_types')) && $entity_type
->hasLinkTemplate('canonical')) {
$base_path = $entity_type
->getLinkTemplate('canonical');
$path = $base_path . '/replicate';
$options = [
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
],
];
if ($entity_type_id == 'node') {
// We delegate the decision of using the admin theme to
// \Drupal\node\EventSubscriber\NodeAdminRouteSubscriber.
$options['_node_operation_route'] = TRUE;
}
else {
// Inherit admin route status from the edit route, if it exists.
$route_name = "entity.{$entity_type_id}.edit_form";
if (($edit_route = $collection
->get($route_name)) && $edit_route
->getOption('_admin_route')) {
$options['_admin_route'] = TRUE;
}
}
$defaults = [
'_entity_form' => "{$entity_type_id}.replicate",
'entity_type_id' => $entity_type_id,
];
$requirements = [
'_replicate_access' => 'TRUE',
];
$route = new Route($path, $defaults, $requirements, $options);
$route_name = "entity.{$entity_type_id}.replicate";
$collection
->add($route_name, $route);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RoutingEvents::DYNAMIC][] = 'onRouteBuild';
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | ||
RouteSubscriber:: |
protected | property | ||
RouteSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RouteSubscriber:: |
public | function | ||
RouteSubscriber:: |
public | function | Creates a new RouteSubscriber instance. |