Commit 4b8a3c4b authored by alexpott's avatar alexpott

Issue #2428035 by amateescu: Bring some sanity into Field UI routes and forms

parent ef0cb6e0
......@@ -108,7 +108,7 @@ public function testCommentTypeEditing() {
$this->drupalGet('admin/structure/comment');
$this->assertRaw('Bar', 'New name was displayed.');
$this->clickLink('Manage fields');
$this->assertUrl(\Drupal::url('entity.comment_type.field_ui_fields', ['comment_type' => 'comment'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
$this->assertUrl(\Drupal::url('entity.comment.field_ui_fields', ['comment_type' => 'comment'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
$this->assertTrue($this->cssSelect('tr#comment-body'), 'Body field exists.');
// Remove the body field.
......
......@@ -71,17 +71,6 @@ function field_ui_entity_type_build(array &$entity_types) {
$entity_types['field_storage_config']->setLinkTemplate('collection', '/admin/reports/fields');
$entity_types['entity_form_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityFormDisplayEditForm');
$entity_types['entity_view_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityViewDisplayEditForm');
foreach ($entity_types as $entity_type) {
if ($bundle = $entity_type->getBundleOf()) {
// To generate links in the UI we use the route names, so we don't have to
// know the exact required routes.
// This allows us to not require route information inside this hook, which
// otherwise could result in circular dependencies.
$entity_type
->setLinkTemplate('field_ui-fields', "/admin/{$entity_type->id()}/fields");
}
}
}
/**
......@@ -130,21 +119,22 @@ function field_ui_entity_operation(EntityInterface $entity) {
$info = $entity->getEntityType();
// Add manage fields and display links if this entity type is the bundle
// of another and that type has field UI enabled.
$entity_manager = \Drupal::entityManager();
if (($bundle_of = $info->getBundleOf()) && $entity_manager->getDefinition($bundle_of)->get('field_ui_base_route')) {
if (($bundle_of = $info->getBundleOf()) && \Drupal::entityManager()->getDefinition($bundle_of)->get('field_ui_base_route')) {
$account = \Drupal::currentUser();
if ($account->hasPermission('administer '. $bundle_of . ' fields')) {
$operations['manage-fields'] = array(
'title' => t('Manage fields'),
'weight' => 15,
'url' => $entity->urlInfo('field_ui-fields'),
'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
}
if ($account->hasPermission('administer '. $bundle_of . ' form display')) {
$operations['manage-form-display'] = array(
'title' => t('Manage form display'),
'weight' => 20,
'url' => Url::fromRoute("entity.entity_form_display.{$entity->getEntityTypeId()}.default", array(
'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
......@@ -153,7 +143,7 @@ function field_ui_entity_operation(EntityInterface $entity) {
$operations['manage-display'] = array(
'title' => t('Manage display'),
'weight' => 25,
'url' => Url::fromRoute("entity.entity_view_display.{$entity->getEntityTypeId()}.default", array(
'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
......
......@@ -4,6 +4,11 @@ services:
arguments: ['@entity.manager']
tags:
- { name: event_subscriber }
field_ui.route_enhancer:
class: Drupal\field_ui\Routing\FieldUiRouteEnhancer
arguments: ['@entity.manager']
tags:
- { name: route_enhancer }
access_check.field_ui.view_mode:
class: Drupal\field_ui\Access\ViewModeAccessCheck
arguments: ['@entity.manager']
......
......@@ -64,7 +64,7 @@ public function __construct(EntityManagerInterface $entity_manager) {
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $form_mode_name = 'default', $bundle = NULL) {
$access = AccessResult::neutral();
if ($entity_type_id = $route->getDefault('entity_type_id')) {
if (!isset($bundle)) {
if (empty($bundle)) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
}
......
......@@ -64,7 +64,7 @@ public function __construct(EntityManagerInterface $entity_manager) {
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $view_mode_name = 'default', $bundle = NULL) {
$access = AccessResult::neutral();
if ($entity_type_id = $route->getDefault('entity_type_id')) {
if (!isset($bundle)) {
if (empty($bundle)) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
}
......
......@@ -30,10 +30,6 @@ class FieldConfigListController extends EntityListController {
* A render array as expected by drupal_render().
*/
public function listing($entity_type_id = NULL, $bundle = NULL, RouteMatchInterface $route_match = NULL) {
if (!$bundle) {
$entity_info = $this->entityManager()->getDefinition($entity_type_id);
$bundle = $route_match->getRawParameter($entity_info->getBundleEntityType());
}
return $this->entityManager()->getListBuilder('field_config')->render($entity_type_id, $bundle);
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
/**
......@@ -30,10 +30,7 @@ class FieldUI {
public static function getOverviewRouteInfo($entity_type_id, $bundle) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
if ($entity_type->get('field_ui_base_route')) {
$bundle_entity_type = static::getRouteBundleEntityType($entity_type);
return new Url("entity.{$bundle_entity_type}.field_ui_fields", array(
$entity_type->getBundleEntityType() => $bundle,
));
return new Url("entity.{$entity_type_id}.field_ui_fields", static::getRouteBundleParameter($entity_type, $bundle));
}
}
......@@ -68,17 +65,18 @@ public static function getNextDestination(array $destinations) {
}
/**
* Gets the bundle entity type used for route names.
* Gets the route parameter that should be used for Field UI routes.
*
* This method returns the bundle entity type, in case there is one.
*
* @param \Drupal\Core\Entity\EntityType $entity_type
* The actual entity type, not the bundle.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The actual entity type, not the bundle (e.g. the content entity type).
* @param string $bundle
* The bundle name.
*
* @return string
* The used entity type ID in the route name.
* @return array
* An array that can be used a route parameter.
*/
public static function getRouteBundleEntityType(EntityType $entity_type) {
return $entity_type->getBundleEntityType() != 'bundle' ? $entity_type->getBundleEntityType() : $entity_type->id();
public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle) {
return array($entity_type->getBundleEntityType() => $bundle);
}
}
......@@ -27,14 +27,6 @@
*/
abstract class EntityDisplayFormBase extends EntityForm {
/**
* The name of the entity type which provides bundles for the entity type
* defined above.
*
* @var string
*/
protected $bundleEntityTypeId;
/**
* The display context. Either 'view' or 'form'.
*
......@@ -82,16 +74,7 @@ public function __construct(FieldTypePluginManagerInterface $field_type_manager,
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
$route_parameters = $route_match->getParameters()->all();
if (isset($route_parameters['bundle'])) {
$bundle = $route_parameters['bundle'];
}
else {
$target_entity_type = $this->entityManager->getDefinition($route_parameters['entity_type_id']);
$this->bundleEntityTypeId = $target_entity_type->getBundleEntityType();
$bundle = $route_parameters[$this->bundleEntityTypeId]->id();
}
return $this->getEntityDisplay($route_parameters['entity_type_id'], $bundle, $route_parameters[$this->displayContext . '_mode_name']);
return $this->getEntityDisplay($route_parameters['entity_type_id'], $route_parameters['bundle'], $route_parameters[$this->displayContext . '_mode_name']);
}
/**
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -106,11 +107,9 @@ protected function getTableHeader() {
*/
protected function getOverviewUrl($mode) {
$entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
return Url::fromRoute('entity.entity_form_display.' . $field_entity_type . '.form_mode', [
$this->bundleEntityTypeId => $this->entity->getTargetBundle(),
return Url::fromRoute('entity.entity_form_display.' . $this->entity->getTargetEntityTypeId() . '.form_mode', [
'form_mode_name' => $mode,
]);
] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
}
/**
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -140,11 +141,9 @@ protected function getTableHeader() {
*/
protected function getOverviewUrl($mode) {
$entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
return Url::fromRoute('entity.entity_view_display.' . $field_entity_type . '.view_mode', [
$this->bundleEntityTypeId => $this->entity->getTargetBundle(),
return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [
'view_mode_name' => $mode,
]);
] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
}
/**
......
......@@ -37,14 +37,6 @@ class FieldStorageAddForm extends FormBase {
*/
protected $bundle;
/**
* The name of the entity type which provides bundles for the entity type
* defined above.
*
* @var string
*/
protected $bundleEntityTypeId;
/**
* The entity manager.
*
......@@ -115,14 +107,10 @@ public static function create(ContainerInterface $container) {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$this->bundleEntityTypeId = $entity_type->getBundleEntityType();
if (!$form_state->get('entity_type_id')) {
$form_state->set('entity_type_id', $entity_type_id);
}
if (!$form_state->get('bundle')) {
$bundle = $bundle ?: $this->getRouteMatch()->getRawParameter($this->bundleEntityTypeId);
$form_state->set('bundle', $bundle);
}
......@@ -323,7 +311,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$destinations = array();
$entity_type = $this->entityManager->getDefinition($this->entityTypeId);
$bundle_entity_type = FieldUI::getRouteBundleEntityType($entity_type);
// Create new field.
if ($values['new_storage_type']) {
......@@ -351,12 +338,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Always show the field settings step, as the cardinality needs to be
// configured for new fields.
$route_parameters = array(
$this->bundleEntityTypeId => $this->bundle,
'field_config' => $field->id(),
);
) + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_storage_edit_form", 'route_parameters' => $route_parameters);
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters);
$destinations[] = array('route_name' => "entity.{$bundle_entity_type}.field_ui_fields", 'route_parameters' => $route_parameters);
$destinations[] = array('route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters);
// Store new field information for any additional submit handlers.
$form_state->set(['fields_added', '_add_new_field'], $values['field_name']);
......@@ -383,11 +369,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configureEntityDisplays($field_name);
$route_parameters = array(
$this->bundleEntityTypeId => $this->bundle,
'field_config' => $field->id(),
);
) + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters);
$destinations[] = array('route_name' => "entity.{$bundle_entity_type}.field_ui_fields", 'route_parameters' => $route_parameters);
$destinations[] = array('route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters);
// Store new field information for any additional submit handlers.
$form_state->set(['fields_added', '_add_existing_field'], $field_name);
......
......@@ -12,7 +12,6 @@
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -60,11 +59,10 @@ public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->get('field_ui_base_route')) {
$bundle_entity_type = FieldUI::getRouteBundleEntityType($entity_type);
$this->derivatives["field_storage_config_add_$entity_type_id"] = array(
'route_name' => "field_ui.field_storage_config_add_$entity_type_id",
'title' => $this->t('Add field'),
'appears_on' => array("entity.$bundle_entity_type.field_ui_fields"),
'appears_on' => array("entity.$entity_type_id.field_ui_fields"),
);
}
}
......
......@@ -13,7 +13,6 @@
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -71,29 +70,27 @@ public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->get('field_ui_base_route')) {
$field_entity_type = FieldUI::getRouteBundleEntityType($entity_type);
$this->derivatives["overview_$field_entity_type"] = array(
'route_name' => "entity.$field_entity_type.field_ui_fields",
$this->derivatives["overview_$entity_type_id"] = array(
'route_name' => "entity.$entity_type_id.field_ui_fields",
'weight' => 1,
'title' => $this->t('Manage fields'),
'base_route' => "entity.$field_entity_type.field_ui_fields",
'base_route' => "entity.$entity_type_id.field_ui_fields",
);
// 'Manage form display' tab.
$this->derivatives["form_display_overview_$field_entity_type"] = array(
'route_name' => "entity.entity_form_display.$field_entity_type.default",
$this->derivatives["form_display_overview_$entity_type_id"] = array(
'route_name' => "entity.entity_form_display.$entity_type_id.default",
'weight' => 2,
'title' => $this->t('Manage form display'),
'base_route' => "entity.$field_entity_type.field_ui_fields",
'base_route' => "entity.$entity_type_id.field_ui_fields",
);
// 'Manage display' tab.
$this->derivatives["display_overview_$field_entity_type"] = array(
'route_name' => "entity.entity_view_display.$field_entity_type.default",
$this->derivatives["display_overview_$entity_type_id"] = array(
'route_name' => "entity.entity_view_display.$entity_type_id.default",
'weight' => 3,
'title' => $this->t('Manage display'),
'base_route' => "entity.$field_entity_type.field_ui_fields",
'base_route' => "entity.$entity_type_id.field_ui_fields",
);
// Field edit tab.
......@@ -117,29 +114,29 @@ public function getDerivativeDefinitions($base_plugin_definition) {
// modes available for customisation. So we define menu items for all
// view modes, and use a route requirement to determine which ones are
// actually visible for a given bundle.
$this->derivatives['field_form_display_default_' . $field_entity_type] = array(
$this->derivatives['field_form_display_default_' . $entity_type_id] = array(
'title' => 'Default',
'route_name' => "entity.entity_form_display.$field_entity_type.default",
'parent_id' => "field_ui.fields:form_display_overview_$field_entity_type",
'route_name' => "entity.entity_form_display.$entity_type_id.default",
'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
'weight' => -1,
);
$this->derivatives['field_display_default_' . $field_entity_type] = array(
$this->derivatives['field_display_default_' . $entity_type_id] = array(
'title' => 'Default',
'route_name' => "entity.entity_view_display.$field_entity_type.default",
'parent_id' => "field_ui.fields:display_overview_$field_entity_type",
'route_name' => "entity.entity_view_display.$entity_type_id.default",
'parent_id' => "field_ui.fields:display_overview_$entity_type_id",
'weight' => -1,
);
// One local task for each form mode.
$weight = 0;
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
$this->derivatives['field_form_display_' . $form_mode . '_' . $field_entity_type] = array(
$this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = array(
'title' => $form_mode_info['label'],
'route_name' => "entity.entity_form_display.$field_entity_type.form_mode",
'route_name' => "entity.entity_form_display.$entity_type_id.form_mode",
'route_parameters' => array(
'form_mode_name' => $form_mode,
),
'parent_id' => "field_ui.fields:form_display_overview_$field_entity_type",
'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
'weight' => $weight++,
);
}
......@@ -147,13 +144,13 @@ public function getDerivativeDefinitions($base_plugin_definition) {
// One local task for each view mode.
$weight = 0;
foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
$this->derivatives['field_display_' . $view_mode . '_' . $field_entity_type] = array(
$this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = array(
'title' => $form_mode_info['label'],
'route_name' => "entity.entity_view_display.$field_entity_type.view_mode",
'route_name' => "entity.entity_view_display.$entity_type_id.view_mode",
'route_parameters' => array(
'view_mode_name' => $view_mode,
),
'parent_id' => "field_ui.fields:display_overview_$field_entity_type",
'parent_id' => "field_ui.fields:display_overview_$entity_type_id",
'weight' => $weight++,
);
}
......@@ -175,21 +172,19 @@ public function getDerivativeDefinitions($base_plugin_definition) {
*/
public function alterLocalTasks(&$local_tasks) {
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
$field_entity_type = FieldUI::getRouteBundleEntityType($entity_type);
if ($route_name = $entity_type->get('field_ui_base_route')) {
$local_tasks["field_ui.fields:overview_$field_entity_type"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:form_display_overview_$field_entity_type"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:display_overview_$field_entity_type"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_form_display_default_$field_entity_type"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_display_default_$field_entity_type"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:form_display_overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:display_overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_form_display_default_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_display_default_$entity_type_id"]['base_route'] = $route_name;
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $field_entity_type]['base_route'] = $route_name;
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $field_entity_type]['base_route'] = $route_name;
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
}
}
......
<?php
/**
* @file
* Contains \Drupal\field_ui\Routing\FieldUiRouteEnhancer.
*/
namespace Drupal\field_ui\Routing;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
* Enhances Field UI routes by adding proper information about the bundle name.
*/
class FieldUiRouteEnhancer implements RouteEnhancerInterface {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a FieldUiRouteEnhancer object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
// Field UI forms only need the actual name of the bundle they're dealing
// with, not an upcasted entity object, so provide a simple way for them
// to get it.
$defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
}
return $defaults;
}
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return ($route->hasOption('_field_ui'));
}
}
......@@ -40,7 +40,6 @@ public function __construct(EntityManagerInterface $manager) {
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->manager->getDefinitions() as $entity_type_id => $entity_type) {
$defaults = array();
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)) {
......@@ -50,12 +49,21 @@ protected function alterRoutes(RouteCollection $collection) {
$options = array();
if (($bundle_entity_type = $entity_type->getBundleEntityType()) && $bundle_entity_type !== 'bundle') {
$options['parameters'][$entity_type->getBundleEntityType()] = array(
'type' => 'entity:' . $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;
}
elseif ($bundle_entity_type == 'bundle') {
$bundle_entity_type = $entity_type_id;
$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 = new Route(
......@@ -63,7 +71,7 @@ protected function alterRoutes(RouteCollection $collection) {
array(
'_form' => '\Drupal\field_ui\Form\FieldEditForm',
'_title_callback' => '\Drupal\field_ui\Form\FieldEditForm::getTitle',
),
) + $defaults,
array('_entity_access' => 'field_config.update'),
$options
);
......@@ -71,7 +79,7 @@ protected function alterRoutes(RouteCollection $collection) {
$route = new Route(
"$path/fields/{field_config}/storage",
array('_form' => '\Drupal\field_ui\Form\FieldStorageEditForm'),
array('_form' => '\Drupal\field_ui\Form\FieldStorageEditForm') + $defaults,
array('_entity_access' => 'field_config.update'),
$options
);
......@@ -79,17 +87,12 @@ protected function alterRoutes(RouteCollection $collection) {
$route = new Route(
"$path/fields/{field_config}/delete",
array('_entity_form' => 'field_config.delete'),
array('_entity_form' => 'field_config.delete') + $defaults,
array('_entity_access' => 'field_config.delete'),
$options
);
$collection->add("entity.field_config.{$entity_type_id}_field_delete_form", $route);
// If the entity type has no bundles, use the entity type.
$defaults['entity_type_id'] = $entity_type_id;
if (!$entity_type->hasKey('bundle')) {
$defaults['bundle'] = $entity_type_id;
}
$route = new Route(
"$path/fields",
array(
......@@ -99,7 +102,7 @@ protected function alterRoutes(RouteCollection $collection) {
array('_permission' => 'administer ' . $entity_type_id . ' fields'),
$options
);
$collection->add("entity.$bundle_entity_type.field_ui_fields", $route);
$collection->add("entity.{$entity_type_id}.field_ui_fields", $route);
$route = new Route(
"$path/fields/add-field",
......@@ -107,7 +110,8 @@ protected function alterRoutes(RouteCollection $collection) {
'_form' => '\Drupal\field_ui\Form\FieldStorageAddForm',
'_title' => 'Add field',
) + $defaults,
array('_permission' => 'administer ' . $entity_type_id . ' fields')
array('_permission' => 'administer ' . $entity_type_id . ' fields'),
$options
);
$collection->add("field_ui.field_storage_config_add_$entity_type_id", $route);
......@@ -121,7 +125,7 @@ protected function alterRoutes(RouteCollection $collection) {
array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'),
$options
);
$collection->add("entity.entity_form_display.$bundle_entity_type.default", $route);
$collection->add("entity.entity_form_display.{$entity_type_id}.default", $route);
$route = new Route(
"$path/form-display/{form_mode_name}",
......@@ -132,7 +136,7 @@ protected function alterRoutes(RouteCollection $collection) {
array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'),
$options
);
$collection->add("entity.entity_form_display.$bundle_entity_type.form_mode", $route);
$collection->add("entity.entity_form_display.{$entity_type_id}.form_mode", $route);
$route = new Route(
"$path/display",
......@@ -144,7 +148,7 @@ protected function alterRoutes(RouteCollection $collection) {
array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'),
$options
);
$collection->add("entity.entity_view_display.$bundle_entity_type.default", $route);
$collection->add("entity.entity_view_display.{$entity_type_id}.default", $route);
$route = new Route(
"$path/display/{view_mode_name}",
......@@ -155,7 +159,7 @@ protected function alterRoutes(RouteCollection $collection) {
array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'),
$options
);
$collection->add("entity.entity_view_display.$bundle_entity_type.view_mode", $route);
$collection->add("entity.entity_view_display.{$entity_type_id}.view_mode", $route);
}
}
}
......
......@@ -381,7 +381,7 @@ function testNoFieldsDisplayOverview() {
))->save();
$this->drupalGet('admin/structure/types/manage/no_fields/display');
$this->assertRaw(t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => \Drupal::url('entity.node_type.field_ui_fields', array('node_type' => 'no_fields')))));
$this->assertRaw(t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => \Drupal::url('entity.node.field_ui_fields', array('node_type' => 'no_fields')))));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment