diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 452f8c7..98f49f2 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -254,11 +254,6 @@ protected function urlRouteParameters($rel) { // The entity ID is needed as a route parameter. $uri_route_parameters[$this->getEntityTypeId()] = $this->id(); - // The 'admin-form' link requires the bundle as a route parameter if the - // entity type uses bundles. - if ($rel == 'admin-form' && $this->getEntityType()->getBundleEntityType() != 'bundle') { - $uri_route_parameters[$this->getEntityType()->getBundleEntityType()] = $this->bundle(); - } return $uri_route_parameters; } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index c827494..b073d7c 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -323,9 +323,9 @@ public function getController($entity_type, $controller_type, $controller_class_ * {@inheritdoc} */ public function getAdminRouteInfo($entity_type_id, $bundle) { - if (($entity_type = $this->getDefinition($entity_type_id, FALSE)) && $admin_form = $entity_type->getLinkTemplate('admin-form')) { + if (($entity_type = $this->getDefinition($entity_type_id, FALSE)) && $route_name = $entity_type->get('field_ui_base_route')) { return array( - 'route_name' => $admin_form, + 'route_name' => $route_name, 'route_parameters' => array( $entity_type->getBundleEntityType() => $bundle, ), diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index ca24505..18036b3 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -195,6 +195,13 @@ class EntityType implements EntityTypeInterface { protected $group_label; /** + * The route name where field UI will use to attach its routes. + * + * @var string + */ + protected $field_ui_base_route; + + /** * Constructs a new EntityType. * * @param array $definition diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index c825620..c9c8c3d 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -41,7 +41,6 @@ * "canonical" = "block_content.edit", * "delete-form" = "block_content.delete", * "edit-form" = "block_content.edit", - * "admin-form" = "block_content.type_edit" * }, * fieldable = TRUE, * translatable = TRUE, @@ -52,7 +51,8 @@ * "label" = "info", * "uuid" = "uuid" * }, - * bundle_entity_type = "block_content_type" + * bundle_entity_type = "block_content_type", + * field_ui_base_route = "block_content.type_edit", * ) */ class BlockContent extends ContentEntityBase implements BlockContentInterface { diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 3d3c42f..065600f 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -48,9 +48,9 @@ * "canonical" = "entity.comment.canonical", * "delete-form" = "entity.comment.delete_form", * "edit-form" = "entity.comment.edit_form", - * "admin-form" = "entity.comment_type.edit_form" * }, - * bundle_entity_type = "comment_type" + * bundle_entity_type = "comment_type", + * field_ui_base_route = "entity.comment_type.edit_form", * ) */ class Comment extends ContentEntityBase implements CommentInterface { diff --git a/core/modules/contact/src/Entity/Message.php b/core/modules/contact/src/Entity/Message.php index b52b32a..f9e8b31 100644 --- a/core/modules/contact/src/Entity/Message.php +++ b/core/modules/contact/src/Entity/Message.php @@ -30,10 +30,8 @@ * "uuid" = "uuid" * }, * bundle_entity_type = "contact_category", + * field_ui_base_route = "entity.contact_category.edit_form", * fieldable = TRUE, - * links = { - * "admin-form" = "entity.contact_category.edit_form" - * } * ) */ class Message extends ContentEntityBase implements MessageInterface { diff --git a/core/modules/field_ui/src/FieldUI.php b/core/modules/field_ui/src/FieldUI.php index bd18010..77ec651 100644 --- a/core/modules/field_ui/src/FieldUI.php +++ b/core/modules/field_ui/src/FieldUI.php @@ -28,7 +28,7 @@ class FieldUI { */ public static function getOverviewRouteInfo($entity_type_id, $bundle) { $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); - if ($entity_type->hasLinkTemplate('admin-form')) { + if ($entity_type->get('field_ui_base_route')) { return new Url("field_ui.overview_$entity_type_id", array( $entity_type->getBundleEntityType() => $bundle, )); diff --git a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php index 35d0218..e473663 100644 --- a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php +++ b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php @@ -69,7 +69,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives = array(); foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->isFieldable() && $entity_type->hasLinkTemplate('admin-form')) { + if ($entity_type->isFieldable() && $entity_type->get('field_ui_base_route')) { $this->derivatives["overview_$entity_type_id"] = array( 'route_name' => "field_ui.overview_$entity_type_id", 'weight' => 1, @@ -172,20 +172,19 @@ public function getDerivativeDefinitions($base_plugin_definition) { */ public function alterLocalTasks(&$local_tasks) { foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info->isFieldable() && $entity_info->hasLinkTemplate('admin-form')) { - $admin_form = $entity_info->getLinkTemplate('admin-form'); - $local_tasks["field_ui.fields:overview_$entity_type"]['base_route'] = $admin_form; - $local_tasks["field_ui.fields:form_display_overview_$entity_type"]['base_route'] = $admin_form; - $local_tasks["field_ui.fields:display_overview_$entity_type"]['base_route'] = $admin_form; - $local_tasks["field_ui.fields:field_form_display_default_$entity_type"]['base_route'] = $admin_form; - $local_tasks["field_ui.fields:field_display_default_$entity_type"]['base_route'] = $admin_form; + if ($entity_info->isFieldable() && $route_name = $entity_info->get('field_ui_base_route')) { + $local_tasks["field_ui.fields:overview_$entity_type"]['base_route'] = $route_name; + $local_tasks["field_ui.fields:form_display_overview_$entity_type"]['base_route'] = $route_name; + $local_tasks["field_ui.fields:display_overview_$entity_type"]['base_route'] = $route_name; + $local_tasks["field_ui.fields:field_form_display_default_$entity_type"]['base_route'] = $route_name; + $local_tasks["field_ui.fields:field_display_default_$entity_type"]['base_route'] = $route_name; foreach ($this->entityManager->getFormModes($entity_type) as $form_mode => $form_mode_info) { - $local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $admin_form; + $local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $route_name; } foreach ($this->entityManager->getViewModes($entity_type) as $view_mode => $form_mode_info) { - $local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type]['base_route'] = $admin_form; + $local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type]['base_route'] = $route_name; } } } diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 9820438..4b371ab 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -41,9 +41,9 @@ public function __construct(EntityManagerInterface $manager) { protected function alterRoutes(RouteCollection $collection) { foreach ($this->manager->getDefinitions() as $entity_type_id => $entity_type) { $defaults = array(); - if ($entity_type->isFieldable() && $entity_type->hasLinkTemplate('admin-form')) { + if ($entity_type->isFieldable() && $route_name = $entity_type->get('field_ui_base_route')) { // Try to get the route from the current collection. - if (!$entity_route = $collection->get($entity_type->getLinkTemplate('admin-form'))) { + if (!$entity_route = $collection->get($route_name)) { continue; } $path = $entity_route->getPath(); diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index b9d5a53..a347682 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -49,13 +49,13 @@ * "uuid" = "uuid" * }, * bundle_entity_type = "node_type", + * field_ui_base_route = "node.type_edit", * permission_granularity = "bundle", * links = { * "canonical" = "node.view", * "delete-form" = "node.delete_confirm", * "edit-form" = "node.page_edit", * "version-history" = "node.revision_overview", - * "admin-form" = "node.type_edit" * } * ) */ diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index bec4cb6..a8aaed0 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -44,9 +44,9 @@ * "canonical" = "entity.shortcut.canonical", * "delete-form" = "entity.shortcut.delete_form", * "edit-form" = "entity.shortcut.canonical", - * "admin-form" = "entity.shortcut.canonical" * }, - * bundle_entity_type = "shortcut_set" + * bundle_entity_type = "shortcut_set", + * field_ui_base_route = "entity.shortcut.canonical", * ) */ class Shortcut extends ContentEntityBase implements ShortcutInterface { diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index e80f34e..2fcf749 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -332,6 +332,8 @@ * - edit-form: Editing form. * - admin-form: Form for editing bundle or entity type settings. * - Other link types specific to your entity type can also be defined. + * - If content entity provides annotation key 'field_ui_base_route' with the + * route where field UI will attach it management forms. * - If your content entity has bundles, you will also need to define a second * plugin to handle the bundles. This plugin is itself a configuration entity * type, so follow the steps here to define it. The machine name ('id' diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php index 4e94184..83097d7 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php @@ -43,8 +43,8 @@ * "canonical" = "entity_test.render", * "edit-form" = "entity_test.edit_entity_test", * "delete-form" = "entity_test.delete_entity_test", - * "admin-form" = "entity_test.admin_entity_test" - * } + * }, + * field_ui_base_route = "entity_test.admin_entity_test", * ) */ class EntityTest extends ContentEntityBase implements EntityOwnerInterface { diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php index e9e7123..6f78e89 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestBaseFieldDisplay.php @@ -32,8 +32,8 @@ * }, * links = { * "edit-form" = "entity_test.edit_entity_test", - * "admin-form" = "entity_test.admin_entity_test" - * } + * }, + * field_ui_base_route = "entity_test.admin_entity_test", * ) */ class EntityTestBaseFieldDisplay extends EntityTest { diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php index c5227e4..524a2d4 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php @@ -40,8 +40,8 @@ * "canonical" = "entity_test.edit_entity_test_mul", * "edit-form" = "entity_test.edit_entity_test_mul", * "delete-form" = "entity_test.delete_entity_test_mul", - * "admin-form" = "entity_test.admin_entity_test_mul" - * } + * }, + * field_ui_base_route = "entity_test.admin_entity_test_mul", * ) */ class EntityTestMul extends EntityTest { diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php index 71bc9b5..b0ec16a 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php @@ -20,9 +20,7 @@ * entity_keys = { * "bundle" = "type", * }, - * links = { - * "admin-form" = "entity_test.admin_entity_test_no_id" - * } + * field_ui_base_route = "entity_test.admin_entity_test_no_id", * ) */ class EntityTestNoId extends EntityTest { diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php index dbe4a20..4e190c4 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php @@ -33,8 +33,8 @@ * links = { * "canonical" = "entity_test.render", * "edit-form" = "entity_test.edit_entity_test_string_id", - * "admin-form" = "entity_test.admin_entity_test_string_id" - * } + * }, + * field_ui_base_route = "entity_test.admin_entity_test_string_id", * ) */ class EntityTestStringId extends EntityTest { diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index d01759f..028883b 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -42,11 +42,11 @@ * "uuid" = "uuid" * }, * bundle_entity_type = "taxonomy_vocabulary", + * field_ui_base_route = "taxonomy.overview_terms", * links = { * "canonical" = "taxonomy.term_page", * "delete-form" = "taxonomy.term_delete", * "edit-form" = "taxonomy.term_edit", - * "admin-form" = "taxonomy.overview_terms" * }, * permission_granularity = "bundle" * ) diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index cd2fb48..8c573b7 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -47,9 +47,9 @@ * links = { * "canonical" = "user.view", * "edit-form" = "user.edit", - * "admin-form" = "user.account_settings", * "cancel-form" = "user.cancel" - * } + * }, + * field_ui_base_route = "user.account_settings", * ) */ class User extends ContentEntityBase implements UserInterface { diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index c86a293..dfadfc9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -448,8 +448,8 @@ public function testGetAdminRouteInfo() { ->method('getBundleEntityType') ->will($this->returnValue('bundle')); $banana->expects($this->once()) - ->method('getLinkTemplate') - ->with('admin-form') + ->method('get') + ->with('field_ui_base_route') ->will($this->returnValue('entity.view')); $this->setUpEntityManager(array( 'apple' => $apple, diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 7f6ff8f..4787e62 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -199,44 +199,6 @@ public function testUrl() { } /** - * Tests the url() method for "admin-form". - * - * @covers ::urlRouteParameters() - */ - public function testUrlForAdminForm() { - $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); - $entity_type->expects($this->exactly(2)) - ->method('getLinkTemplates') - ->will($this->returnValue(array( - 'admin-form' => 'test_entity_type.admin_form', - ))); - $entity_type->expects($this->exactly(2)) - ->method('getBundleEntityType') - ->will($this->returnValue('test_entity_type_bundle')); - - $this->entityManager - ->expects($this->exactly(4)) - ->method('getDefinition') - ->with('test_entity_type') - ->will($this->returnValue($entity_type)); - - $this->urlGenerator->expects($this->once()) - ->method('generateFromRoute') - ->with('test_entity_type.admin_form', array( - 'test_entity_type_bundle' => 'test_entity_bundle', - 'test_entity_type' => 'test_entity_id', - )) - ->will($this->returnValue('entity/test_entity_type/test_entity_bundle/test_entity_id')); - - $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'), '', TRUE, TRUE, TRUE, array('bundle')); - $entity->expects($this->any()) - ->method('bundle') - ->will($this->returnValue('test_entity_bundle')); - - $this->assertSame('entity/test_entity_type/test_entity_bundle/test_entity_id', $entity->url('admin-form')); - } - - /** * Tests the getPathByAlias() method. * * @covers ::getSystemPath()