class RouteSubscriber in Field tools 8
Subscriber for Field Tools routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\field_tools\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\field_tools\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($route_name = $entity_type
->get('field_ui_base_route')) {
// Try to get the route from the current collection.
if (!($entity_route = $collection
->get($route_name))) {
continue;
}
$path = $entity_route
->getPath();
$options = $entity_route
->getOptions();
if ($bundle_entity_type = $entity_type
->getBundleEntityType()) {
$options['parameters'][$bundle_entity_type] = array(
'type' => 'entity:' . $bundle_entity_type,
);
}
// Special parameter used to easily recognize all Field UI routes.
$options['_field_ui'] = TRUE;
$defaults = array(
'entity_type_id' => $entity_type_id,
);
// If the entity type has no bundles and it doesn't use {bundle} in its
// admin path, use the entity type.
if (strpos($path, '{bundle}') === FALSE) {
$defaults['bundle'] = !$entity_type
->hasKey('bundle') ? $entity_type_id : '';
}
// Route for cloning a single field.
$route = new Route("{$path}/fields/{field_config}/clone", array(
'_entity_form' => 'field_config.clone',
'_title' => 'Clone field',
) + $defaults, array(
'_entity_access' => 'field_config.update',
), $options);
$collection
->add("entity.field_config.{$entity_type_id}_field_tools_clone_form", $route);
// Route for bulk cloning fields.
$route = new Route("{$path}/fields/tools/clone-fields", array(
'_form' => '\\Drupal\\field_tools\\Form\\FieldBulkCloneForm',
'_title' => 'Clone fields',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type_id . ' fields',
), $options);
$collection
->add("field_tools.field_bulk_clone_{$entity_type_id}", $route);
// Route for bulk cloning displays.
$route = new Route("{$path}/fields/tools/clone-displays", array(
'_form' => '\\Drupal\\field_tools\\Form\\EntityDisplayBulkCloneForm',
'_title' => 'Clone displays',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type_id . ' fields',
), $options);
$collection
->add("field_tools.displays_clone_{$entity_type_id}", $route);
// Route for bulk copying field display settings.
$route = new Route("{$path}/fields/tools/copy-display-settings", array(
'_form' => '\\Drupal\\field_tools\\Form\\EntityDisplaySettingsBulkCopyForm',
'_title' => 'Copy display settings',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type_id . ' fields',
), $options);
$collection
->add("field_tools.displays_settings_copy_{$entity_type_id}", $route);
// Route for exporting field configuration to code.
$route = new Route("{$path}/fields/tools/export-to-code", array(
'_form' => '\\Drupal\\field_tools\\Form\\ConfigFieldsExportToCodeForm',
'_title' => 'Export to base fields code',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type_id . ' fields',
), $options);
$collection
->add("field_tools.export_to_code_{$entity_type_id}", $route);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = array(
'onAlterRoutes',
-100,
);
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The entity type manager. | |
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 | Constructs a RouteSubscriber object. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |