diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index cf2583dee119de9c2b95d8a5bf9da3828aedae51..a9d20011a04c96ae88696d33ec18057a4963dbba 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 8cfb35c0f43758abdc0933fbd9052467328e48f4..5a3c22de3c6f9e40b5b966f74f42b42423c7617f 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -329,20 +329,6 @@ public function getController($entity_type, $controller_type, $controller_class_ return $this->controllers[$controller_type][$entity_type]; } - /** - * {@inheritdoc} - */ - public function getAdminRouteInfo($entity_type_id, $bundle) { - if (($entity_type = $this->getDefinition($entity_type_id, FALSE)) && $admin_form = $entity_type->getLinkTemplate('admin-form')) { - return array( - 'route_name' => $admin_form, - 'route_parameters' => array( - $entity_type->getBundleEntityType() => $bundle, - ), - ); - } - } - /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index f5c2374ea2a5ea4178887ec325b4ff51ef8e7a67..18c7c8bb241174632a6562577f88e09914ea845b 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -116,22 +116,6 @@ public function getFieldMapByFieldType($field_type); */ public function getAccessControlHandler($entity_type); - /** - * Returns the route information for an entity type's bundle. - * - * @param string $entity_type_id - * The entity type. - * @param string $bundle - * The name of the bundle. - * - * @return array - * An associative array with the following keys: - * - route_name: The name of the route. - * - route_parameters: (optional) An associative array of parameter names - * and values. - */ - public function getAdminRouteInfo($entity_type_id, $bundle); - /** * Creates a new storage instance. * diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 9e607d876af05d7a9150c8cc6e46a3fa9126158e..110fcee7293ad602b587f5b0c29a766faa2b45b0 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -203,6 +203,13 @@ class EntityType implements EntityTypeInterface { */ protected $group_label; + /** + * The route name used by field UI to attach its management pages. + * + * @var string + */ + protected $field_ui_base_route; + /** * Constructs a new EntityType. * diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index c06d4e88f943d5acd179b62b95be178b20f7cd20..b00426115746413acf33def2bb2cb6bd463c02c6 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -41,7 +41,6 @@ * "canonical" = "entity.block_content.canonical", * "delete-form" = "entity.block_content.delete_form", * "edit-form" = "entity.block_content.canonical", - * "admin-form" = "entity.block_content_type.edit_form" * }, * 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 = "entity.block_content_type.edit_form", * ) */ 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 bda01444334ed9f0419f1765ce490ec204c58b68..edde6c3acdca382effd3e2dd5d6e2acf457a1f40 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -49,9 +49,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 ac361de8f6e023d36dee09a4efcaff27cc3bbfcf..9cf50bccb40c575082cc2cd2d7b9fb40a5c9799d 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_form", + * field_ui_base_route = "entity.contact_form.edit_form", * fieldable = TRUE, - * links = { - * "admin-form" = "entity.contact_form.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 bd18010640858c3b6b276bfa5446089e71b7592f..77ec6513e2b6217b9833d9f7556804514a54f0de 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 35d021802dff4d186d1552ca4e635da9eb97eb94..758a98b38a894d50ff0914b8d915ee15cfe36e8d 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, @@ -171,21 +171,20 @@ public function getDerivativeDefinitions($base_plugin_definition) { * An array of local tasks plugin definitions, keyed by plugin ID. */ 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; - - 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; + foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { + if ($entity_type->isFieldable() && $route_name = $entity_type->get('field_ui_base_route')) { + $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 . '_' . $entity_type_id]['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; + foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) { + $local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type_id]['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 982043805a625199319cd33a04c9a43be50837e2..4b371ab3cd037404eb31c9b59a4109c071ad6547 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 fcfb8dee4512b28fe13379e39d4625e7e962b0cb..c57e3af28e77dea5a799baa8cbe25d6d2ea1d70c 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -50,13 +50,13 @@ * "uuid" = "uuid" * }, * bundle_entity_type = "node_type", + * field_ui_base_route = "entity.node_type.edit_form", * permission_granularity = "bundle", * links = { * "canonical" = "entity.node.canonical", * "delete-form" = "entity.node.delete_form", * "edit-form" = "entity.node.edit_form", * "version-history" = "entity.node.version_history", - * "admin-form" = "entity.node_type.edit_form" * } * ) */ diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 6a3ec86a31dcc9635017f0abecfe55a255b8cbd5..706ef0a19400d8a2a69e39cca1166f0725ca5409 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 e099db8805bb5a03287201394e48b080d7b0d6a9..7805b0da38a24b7ee514789be57842050f739aa3 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -332,8 +332,12 @@ * own pages) or edit the entity. * - delete-form: Confirmation form to delete the entity. * - 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 your content entity is fieldable, provide 'field_ui_base_route' + * annotation, giving the name of the route that the Manage Fields, Manage + * Display, and Manage Form Display pages from the Field UI module will be + * attached to. This is usually the bundle settings edit page, or an entity + * type settings page if there are no bundles. * - 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 5fb498315c9d3a7865a1547782cd5df82f76e1f1..2470c8cd0b1a788af85ffccd0fe72c5880bf729a 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 @@ -44,8 +44,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 e235f6c25a4aed73b385ca5c0d8a47f0cb0bb582..79cf39f2306f4b9b39c6eecc6b4dd40c84b3ccfe 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 b5ba803c46fd5f02fde2ac9605f56bde777cf1df..a61f41b80d946a0d64e5b54fa2996f8980c97c74 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 71bc9b5365426a2a52004246254ae0532c74e716..b0ec16a818f751e30fe5208b3c8001589e3f72da 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 de9e47a6d8bdfbbe440aa664adc9d1d165782887..eb70bddbfada4a31f4020cfde6cc95c1d0b10931 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 79254dd4dac5b40168e93348c1572b13bc0194a1..e50e3a0fb0ad6f387bdd1cd794d3186b660fe05f 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -43,11 +43,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 6da2f0e95ca6706cb84e39c5a8a3b6eff5ec29f8..ffc9dfcfe6aa99aeb34af724a6fbd474e580718b 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -49,9 +49,9 @@ * links = { * "canonical" = "entity.user.canonical", * "edit-form" = "entity.user.edit_form", - * "admin-form" = "entity.user.admin_form", - * "cancel-form" = "entity.user.cancel_form" - * } + * "cancel-form" = "entity.user.cancel_form", + * }, + * field_ui_base_route = "entity.user.admin_form", * ) */ 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 6022ecf2df15b6cb54bcf06df84d9d26ed2da6e0..96db0754f372f07f06eabe9e4bc1848ce9bbb11e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -436,36 +436,6 @@ public function testGetControllerMissingController() { $this->entityManager->getController('test_entity_type', 'storage'); } - /** - * Tests the getAdminRouteInfo() method. - * - * @covers ::getAdminRouteInfo() - */ - public function testGetAdminRouteInfo() { - $apple = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); - $banana = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); - $banana->expects($this->once()) - ->method('getBundleEntityType') - ->will($this->returnValue('bundle')); - $banana->expects($this->once()) - ->method('getLinkTemplate') - ->with('admin-form') - ->will($this->returnValue('entity.view')); - $this->setUpEntityManager(array( - 'apple' => $apple, - 'banana' => $banana, - )); - - $expected = array( - 'route_name' => 'entity.view', - 'route_parameters' => array( - 'bundle' => 'chiquita', - ), - ); - $this->assertSame($expected, $this->entityManager->getAdminRouteInfo('banana', 'chiquita')); - $this->assertNull($this->entityManager->getAdminRouteInfo('apple', 'delicious')); - } - /** * Tests the getBaseFieldDefinitions() method. * diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 7f6ff8fa310e69eaa1e62e52d2f60f0661826016..4787e6293172c535a7c409ca40d659972717e544 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -198,44 +198,6 @@ public function testUrl() { $this->assertSame('http://drupal/entity/test_entity_type/test_entity_id', $valid_entity->url('canonical', array('absolute' => TRUE))); } - /** - * 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. *