Commit f1713d57 authored by alexpott's avatar alexpott

Issue #2309187 by andypost | Crell: Fixed double-link-entry between Entity and Entity Type classes.

parent 4192e7d2
...@@ -254,11 +254,6 @@ protected function urlRouteParameters($rel) { ...@@ -254,11 +254,6 @@ protected function urlRouteParameters($rel) {
// The entity ID is needed as a route parameter. // The entity ID is needed as a route parameter.
$uri_route_parameters[$this->getEntityTypeId()] = $this->id(); $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; return $uri_route_parameters;
} }
......
...@@ -329,20 +329,6 @@ public function getController($entity_type, $controller_type, $controller_class_ ...@@ -329,20 +329,6 @@ public function getController($entity_type, $controller_type, $controller_class_
return $this->controllers[$controller_type][$entity_type]; 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} * {@inheritdoc}
*/ */
......
...@@ -116,22 +116,6 @@ public function getFieldMapByFieldType($field_type); ...@@ -116,22 +116,6 @@ public function getFieldMapByFieldType($field_type);
*/ */
public function getAccessControlHandler($entity_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. * Creates a new storage instance.
* *
......
...@@ -203,6 +203,13 @@ class EntityType implements EntityTypeInterface { ...@@ -203,6 +203,13 @@ class EntityType implements EntityTypeInterface {
*/ */
protected $group_label; 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. * Constructs a new EntityType.
* *
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
* "canonical" = "entity.block_content.canonical", * "canonical" = "entity.block_content.canonical",
* "delete-form" = "entity.block_content.delete_form", * "delete-form" = "entity.block_content.delete_form",
* "edit-form" = "entity.block_content.canonical", * "edit-form" = "entity.block_content.canonical",
* "admin-form" = "entity.block_content_type.edit_form"
* }, * },
* fieldable = TRUE, * fieldable = TRUE,
* translatable = TRUE, * translatable = TRUE,
...@@ -52,7 +51,8 @@ ...@@ -52,7 +51,8 @@
* "label" = "info", * "label" = "info",
* "uuid" = "uuid" * "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 { class BlockContent extends ContentEntityBase implements BlockContentInterface {
......
...@@ -49,9 +49,9 @@ ...@@ -49,9 +49,9 @@
* "canonical" = "entity.comment.canonical", * "canonical" = "entity.comment.canonical",
* "delete-form" = "entity.comment.delete_form", * "delete-form" = "entity.comment.delete_form",
* "edit-form" = "entity.comment.edit_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 { class Comment extends ContentEntityBase implements CommentInterface {
......
...@@ -30,10 +30,8 @@ ...@@ -30,10 +30,8 @@
* "uuid" = "uuid" * "uuid" = "uuid"
* }, * },
* bundle_entity_type = "contact_form", * bundle_entity_type = "contact_form",
* field_ui_base_route = "entity.contact_form.edit_form",
* fieldable = TRUE, * fieldable = TRUE,
* links = {
* "admin-form" = "entity.contact_form.edit_form"
* }
* ) * )
*/ */
class Message extends ContentEntityBase implements MessageInterface { class Message extends ContentEntityBase implements MessageInterface {
......
...@@ -28,7 +28,7 @@ class FieldUI { ...@@ -28,7 +28,7 @@ class FieldUI {
*/ */
public static function getOverviewRouteInfo($entity_type_id, $bundle) { public static function getOverviewRouteInfo($entity_type_id, $bundle) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); $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( return new Url("field_ui.overview_$entity_type_id", array(
$entity_type->getBundleEntityType() => $bundle, $entity_type->getBundleEntityType() => $bundle,
)); ));
......
...@@ -69,7 +69,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { ...@@ -69,7 +69,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array(); $this->derivatives = array();
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { 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( $this->derivatives["overview_$entity_type_id"] = array(
'route_name' => "field_ui.overview_$entity_type_id", 'route_name' => "field_ui.overview_$entity_type_id",
'weight' => 1, 'weight' => 1,
...@@ -171,21 +171,20 @@ public function getDerivativeDefinitions($base_plugin_definition) { ...@@ -171,21 +171,20 @@ public function getDerivativeDefinitions($base_plugin_definition) {
* An array of local tasks plugin definitions, keyed by plugin ID. * An array of local tasks plugin definitions, keyed by plugin ID.
*/ */
public function alterLocalTasks(&$local_tasks) { public function alterLocalTasks(&$local_tasks) {
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_info->isFieldable() && $entity_info->hasLinkTemplate('admin-form')) { if ($entity_type->isFieldable() && $route_name = $entity_type->get('field_ui_base_route')) {
$admin_form = $entity_info->getLinkTemplate('admin-form'); $local_tasks["field_ui.fields:overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:overview_$entity_type"]['base_route'] = $admin_form; $local_tasks["field_ui.fields:form_display_overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:form_display_overview_$entity_type"]['base_route'] = $admin_form; $local_tasks["field_ui.fields:display_overview_$entity_type_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:display_overview_$entity_type"]['base_route'] = $admin_form; $local_tasks["field_ui.fields:field_form_display_default_$entity_type_id"]['base_route'] = $route_name;
$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_id"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_display_default_$entity_type"]['base_route'] = $admin_form;
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
foreach ($this->entityManager->getFormModes($entity_type) as $form_mode => $form_mode_info) { $local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type_id]['base_route'] = $route_name;
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $admin_form;
} }
foreach ($this->entityManager->getViewModes($entity_type) as $view_mode => $form_mode_info) { foreach ($this->entityManager->getViewModes($entity_type_id) 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_id]['base_route'] = $route_name;
} }
} }
} }
......
...@@ -41,9 +41,9 @@ public function __construct(EntityManagerInterface $manager) { ...@@ -41,9 +41,9 @@ public function __construct(EntityManagerInterface $manager) {
protected function alterRoutes(RouteCollection $collection) { protected function alterRoutes(RouteCollection $collection) {
foreach ($this->manager->getDefinitions() as $entity_type_id => $entity_type) { foreach ($this->manager->getDefinitions() as $entity_type_id => $entity_type) {
$defaults = array(); $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. // 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; continue;
} }
$path = $entity_route->getPath(); $path = $entity_route->getPath();
......
...@@ -50,13 +50,13 @@ ...@@ -50,13 +50,13 @@
* "uuid" = "uuid" * "uuid" = "uuid"
* }, * },
* bundle_entity_type = "node_type", * bundle_entity_type = "node_type",
* field_ui_base_route = "entity.node_type.edit_form",
* permission_granularity = "bundle", * permission_granularity = "bundle",
* links = { * links = {
* "canonical" = "entity.node.canonical", * "canonical" = "entity.node.canonical",
* "delete-form" = "entity.node.delete_form", * "delete-form" = "entity.node.delete_form",
* "edit-form" = "entity.node.edit_form", * "edit-form" = "entity.node.edit_form",
* "version-history" = "entity.node.version_history", * "version-history" = "entity.node.version_history",
* "admin-form" = "entity.node_type.edit_form"
* } * }
* ) * )
*/ */
......
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
* "canonical" = "entity.shortcut.canonical", * "canonical" = "entity.shortcut.canonical",
* "delete-form" = "entity.shortcut.delete_form", * "delete-form" = "entity.shortcut.delete_form",
* "edit-form" = "entity.shortcut.canonical", * "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 { class Shortcut extends ContentEntityBase implements ShortcutInterface {
......
...@@ -332,8 +332,12 @@ ...@@ -332,8 +332,12 @@
* own pages) or edit the entity. * own pages) or edit the entity.
* - delete-form: Confirmation form to delete the entity. * - delete-form: Confirmation form to delete the entity.
* - edit-form: Editing form. * - 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. * - 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 * - 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 * 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' * type, so follow the steps here to define it. The machine name ('id'
......
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
* "canonical" = "entity_test.render", * "canonical" = "entity_test.render",
* "edit-form" = "entity_test.edit_entity_test", * "edit-form" = "entity_test.edit_entity_test",
* "delete-form" = "entity_test.delete_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 { class EntityTest extends ContentEntityBase implements EntityOwnerInterface {
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
* }, * },
* links = { * links = {
* "edit-form" = "entity_test.edit_entity_test", * "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 { class EntityTestBaseFieldDisplay extends EntityTest {
......
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
* "canonical" = "entity_test.edit_entity_test_mul", * "canonical" = "entity_test.edit_entity_test_mul",
* "edit-form" = "entity_test.edit_entity_test_mul", * "edit-form" = "entity_test.edit_entity_test_mul",
* "delete-form" = "entity_test.delete_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 { class EntityTestMul extends EntityTest {
......
...@@ -20,9 +20,7 @@ ...@@ -20,9 +20,7 @@
* entity_keys = { * entity_keys = {
* "bundle" = "type", * "bundle" = "type",
* }, * },
* links = { * field_ui_base_route = "entity_test.admin_entity_test_no_id",
* "admin-form" = "entity_test.admin_entity_test_no_id"
* }
* ) * )
*/ */
class EntityTestNoId extends EntityTest { class EntityTestNoId extends EntityTest {
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
* links = { * links = {
* "canonical" = "entity_test.render", * "canonical" = "entity_test.render",
* "edit-form" = "entity_test.edit_entity_test_string_id", * "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 { class EntityTestStringId extends EntityTest {
......
...@@ -43,11 +43,11 @@ ...@@ -43,11 +43,11 @@
* "uuid" = "uuid" * "uuid" = "uuid"
* }, * },
* bundle_entity_type = "taxonomy_vocabulary", * bundle_entity_type = "taxonomy_vocabulary",
* field_ui_base_route = "taxonomy.overview_terms",
* links = { * links = {
* "canonical" = "taxonomy.term_page", * "canonical" = "taxonomy.term_page",
* "delete-form" = "taxonomy.term_delete", * "delete-form" = "taxonomy.term_delete",
* "edit-form" = "taxonomy.term_edit", * "edit-form" = "taxonomy.term_edit",
* "admin-form" = "taxonomy.overview_terms"
* }, * },
* permission_granularity = "bundle" * permission_granularity = "bundle"
* ) * )
......
...@@ -49,9 +49,9 @@ ...@@ -49,9 +49,9 @@
* links = { * links = {
* "canonical" = "entity.user.canonical", * "canonical" = "entity.user.canonical",
* "edit-form" = "entity.user.edit_form", * "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 { class User extends ContentEntityBase implements UserInterface {
......
...@@ -436,36 +436,6 @@ public function testGetControllerMissingController() { ...@@ -436,36 +436,6 @@ public function testGetControllerMissingController() {
$this->entityManager->getController('test_entity_type', 'storage'); $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. * Tests the getBaseFieldDefinitions() method.
* *
......
...@@ -198,44 +198,6 @@ public function testUrl() { ...@@ -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))); $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. * Tests the getPathByAlias() method.
* *
......
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