Subscriber for Field UI routes.
Expanded class hierarchy of RouteSubscriber
class RouteSubscriber implements EventSubscriberInterface {
/**
* The entity type manager
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $manager;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityManager $manager
* The entity type manager.
*/
public function __construct(EntityManager $manager) {
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RoutingEvents::DYNAMIC] = 'routes';
return $events;
}
/**
* Adds routes for the Field UI.
*/
public function routes(RouteBuildEvent $event) {
$collection = $event
->getRouteCollection();
foreach ($this->manager
->getDefinitions() as $entity_type => $entity_info) {
$defaults = array();
if ($entity_info['fieldable'] && isset($entity_info['route_base_path'])) {
$path = $entity_info['route_base_path'];
$route = new Route("{$path}/fields/{field_instance}", array(
'_form' => '\\Drupal\\field_ui\\Form\\FieldInstanceEditForm',
), array(
'_permission' => 'administer ' . $entity_type . ' fields',
));
$collection
->add("field_ui.instance_edit.{$entity_type}", $route);
$route = new Route("{$path}/fields/{field_instance}/field", array(
'_form' => '\\Drupal\\field_ui\\Form\\FieldEditForm',
), array(
'_permission' => 'administer ' . $entity_type . ' fields',
));
$collection
->add("field_ui.field_edit.{$entity_type}", $route);
$route = new Route("{$path}/fields/{field_instance}/widget-type", array(
'_form' => '\\Drupal\\field_ui\\Form\\FieldWidgetTypeForm',
), array(
'_permission' => 'administer ' . $entity_type . ' fields',
));
$collection
->add("field_ui.widget_type.{$entity_type}", $route);
$route = new Route("{$path}/fields/{field_instance}/delete", array(
'_form' => '\\Drupal\\field_ui\\Form\\FieldDeleteForm',
), array(
'_permission' => 'administer ' . $entity_type . ' fields',
));
$collection
->add("field_ui.delete.{$entity_type}", $route);
// If the entity type has no bundles, use the entity type.
$defaults['entity_type'] = $entity_type;
if (empty($entity_info['entity_keys']['bundle'])) {
$defaults['bundle'] = $entity_type;
}
$route = new Route("{$path}/fields", array(
'_form' => '\\Drupal\\field_ui\\FieldOverview',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type . ' fields',
));
$collection
->add("field_ui.overview.{$entity_type}", $route);
$route = new Route("{$path}/display", array(
'_form' => '\\Drupal\\field_ui\\DisplayOverview',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type . ' display',
));
$collection
->add("field_ui.display_overview.{$entity_type}", $route);
foreach (entity_get_view_modes($entity_type) as $view_mode => $view_mode_info) {
$route = new Route("{$path}/display/{$view_mode}", array(
'_form' => '\\Drupal\\field_ui\\DisplayOverview',
'view_mode' => $view_mode,
) + $defaults, array(
'_field_ui_view_mode_access' => 'administer ' . $entity_type . ' display',
));
$collection
->add("field_ui.display_overview.{$entity_type}.{$view_mode}", $route);
}
}
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The entity type manager | |
RouteSubscriber:: |
public | function | Constructs a RouteSubscriber object. | |
RouteSubscriber:: |
public | function | Adds routes for the Field UI. | |
RouteSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface:: |