diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index c8b9eda..aa1cb34 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -188,4 +188,11 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { } } + /** + * {@inheritdoc} + */ + public function uri() { + return parent::uri('edit-form'); + } + } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 68404ba..7a86e68 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -149,36 +149,82 @@ public function label($langcode = NULL) { } /** - * Implements \Drupal\Core\Entity\EntityInterface::uri(). + * {@inheritdoc}. */ - public function uri() { - $bundle = $this->bundle(); - // A bundle-specific callback takes precedence over the generic one for the - // entity type. + public function uri($rel = 'canonical') { $entity_info = $this->entityInfo(); - $bundles = entity_get_bundles($this->entityType); - if (isset($bundles[$bundle]['uri_callback'])) { - $uri_callback = $bundles[$bundle]['uri_callback']; - } - elseif (isset($entity_info['uri_callback'])) { - $uri_callback = $entity_info['uri_callback']; + + $link_templates = isset($entity_info['links']) ? $entity_info['links'] : array(); + + if (isset($link_templates[$rel])) { + $template = $link_templates[$rel]; + $replacements = $this->uriPlaceholderReplacements(); + $uri['path'] = str_replace(array_keys($replacements), array_values($replacements), $template); + + // @todo Remove this once http://drupal.org/node/1888424 is in and we can + // move the BC handling of / vs. no-/ to the generator. + $uri['path'] = trim($uri['path'], '/'); + + // Pass the entity data to url() so that alter functions do not need to + // look up this entity again. + $uri['options']['entity_type'] = $this->entityType; + $uri['options']['entity'] = $this; + return $uri; } - // Invoke the callback to get the URI. If there is no callback, use the - // default URI format. - if (isset($uri_callback) && function_exists($uri_callback)) { - $uri = $uri_callback($this); + // For a canonical link (that is, a link to self), use the default logic. + // Other relationship types are not supported by this logic. + if ($rel == 'canonical') { + $bundle = $this->bundle(); + // A bundle-specific callback takes precedence over the generic one for the + // entity type. + $bundles = entity_get_bundles($this->entityType); + if (isset($bundles[$bundle]['uri_callback'])) { + $uri_callback = $bundles[$bundle]['uri_callback']; + } + elseif (isset($entity_info['uri_callback'])) { + $uri_callback = $entity_info['uri_callback']; + } + + // Invoke the callback to get the URI. If there is no callback, use the + // default URI format. + if (isset($uri_callback) && function_exists($uri_callback)) { + $uri = $uri_callback($this); + } + else { + $uri = array( + 'path' => 'entity/' . $this->entityType . '/' . $this->id(), + ); + } + // Pass the entity data to url() so that alter functions do not need to + // look up this entity again. + $uri['options']['entity_type'] = $this->entityType; + $uri['options']['entity'] = $this; + return $uri; } - else { - $uri = array( - 'path' => 'entity/' . $this->entityType . '/' . $this->id(), + } + + /** + * Returns an array of placeholders for this entity. + * + * Individual entity classes may override this method to add additional + * placeholders if desired. If so, they should be sure to replicate the + * property caching logic. + * + * @return array + * An array of URI placeholders. + */ + protected function uriPlaceholderReplacements() { + if (empty($this->uriPlaceholderReplacements)) { + $this->uriPlaceholderReplacements = array( + '{entityType}' => $this->entityType(), + '{bundle}' => $this->bundle(), + '{id}' => $this->id(), + '{uuid}' => $this->uuid(), + '{' . $this->entityType() . '}' => $this->id(), ); } - // Pass the entity data to url() so that alter functions do not need to - // look up this entity again. - $uri['options']['entity_type'] = $this->entityType; - $uri['options']['entity'] = $this; - return $uri; + return $this->uriPlaceholderReplacements; } /** diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index d0b6b4c..4e52423 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -217,61 +217,6 @@ public function uuid() { } /** - * {@inheritdoc} - */ - public function uri($rel = 'canonical') { - $entity_info = $this->entityInfo(); - - $link_templates = isset($entity_info['links']) ? $entity_info['links'] : array(); - - if (isset($link_templates[$rel])) { - $template = $link_templates[$rel]; - $replacements = $this->uriPlaceholderReplacements(); - $uri['path'] = str_replace(array_keys($replacements), array_values($replacements), $template); - - // @todo Remove this once http://drupal.org/node/1888424 is in and we can - // move the BC handling of / vs. no-/ to the generator. - $uri['path'] = trim($uri['path'], '/'); - - // Pass the entity data to url() so that alter functions do not need to - // look up this entity again. - $uri['options']['entity_type'] = $this->entityType; - $uri['options']['entity'] = $this; - return $uri; - } - - // For a canonical link (that is, a link to self), look up the stack for - // default logic. Other relationship types are not supported by parent - // classes. - if ($rel == 'canonical') { - return parent::uri(); - } - } - - /** - * Returns an array of placeholders for this entity. - * - * Individual entity classes may override this method to add additional - * placeholders if desired. If so, they should be sure to replicate the - * property caching logic. - * - * @return array - * An array of URI placeholders. - */ - protected function uriPlaceholderReplacements() { - if (empty($this->uriPlaceholderReplacements)) { - $this->uriPlaceholderReplacements = array( - '{entityType}' => $this->entityType(), - '{bundle}' => $this->bundle(), - '{id}' => $this->id(), - '{uuid}' => $this->uuid(), - '{' . $this->entityType() . '}' => $this->id(), - ); - } - return $this->uriPlaceholderReplacements; - } - - /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::get(). */ public function get($property_name) { diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php index cb1a57e..b522464 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php @@ -37,6 +37,9 @@ * "id" = "id", * "label" = "label", * "uuid" = "uuid" + * }, + * links = { + * "edit-form" = "admin/structure/block/custom-blocks/manage/{custom_block_type}" * } * ) */ @@ -78,19 +81,6 @@ class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterfa public $description; /** - * Overrides \Drupal\Core\Entity\Entity::uri(). - */ - public function uri() { - return array( - 'path' => 'admin/structure/block/custom-blocks/manage/' . $this->id(), - 'options' => array( - 'entity_type' => $this->entityType, - 'entity' => $this, - ) - ); - } - - /** * {@inheritdoc} */ public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index faaccde..aeac9c3 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -62,7 +62,7 @@ function testCRUD() { $this->assertIdentical($empty->isNewRevision(), FALSE); $this->assertIdentical($empty->entityType(), 'config_test'); $uri = $empty->uri(); - $this->assertIdentical($uri['path'], 'admin/structure/config_test/manage/'); + $this->assertIdentical($uri['path'], 'admin/structure/config_test/manage'); $this->assertIdentical($empty->isDefaultRevision(), TRUE); // Verify that an empty entity cannot be saved. diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index a985921..86fe4a9 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -11,18 +11,6 @@ require_once dirname(__FILE__) . '/config_test.hooks.inc'; /** - * Entity URI callback. - * - * @param Drupal\config_test\Entity\ConfigTest $config_test - * A ConfigTest entity. - */ -function config_test_uri(ConfigTest $config_test) { - return array( - 'path' => 'admin/structure/config_test/manage/' . $config_test->id(), - ); -} - -/** * Implements hook_menu(). */ function config_test_menu() { diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php index e909f4d..6c55057 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php @@ -24,12 +24,14 @@ * "default" = "Drupal\config_test\ConfigTestFormController" * } * }, - * uri_callback = "config_test_uri", * config_prefix = "config_query_test.dynamic", * entity_keys = { * "id" = "id", * "label" = "label", * "uuid" = "uuid" + * }, + * links = { + * "edit-form" = "admin/structure/config_test/manage/{config_query_test}" * } * ) * diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php index c355e25..c4d330e 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php @@ -28,13 +28,15 @@ * }, * "access" = "Drupal\config_test\ConfigTestAccessController" * }, - * uri_callback = "config_test_uri", * config_prefix = "config_test.dynamic", * entity_keys = { * "id" = "id", * "label" = "label", * "uuid" = "uuid", * "status" = "status" + * }, + * links = { + * "edit-form" = "admin/structure/config_test/manage/{config_test}" * } * ) */ diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 2b1d8bf..298ca7f 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -241,21 +241,6 @@ function contact_category_load($id) { } /** - * Entity URI callback. - * - * @param Drupal\contact\Entity\Category $category - * A contact category entity. - * - * @return array - * An array with 'path' as the key and the path to the category as the value. - */ -function contact_category_uri(Category $category) { - return array( - 'path' => 'admin/structure/contact/manage/' . $category->id(), - ); -} - -/** * Implements hook_mail(). */ function contact_mail($key, &$message, $params) { diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Category.php b/core/modules/contact/lib/Drupal/contact/Entity/Category.php index 7f633fc..646dcad 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Category.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Category.php @@ -30,13 +30,15 @@ * "delete" = "Drupal\contact\Form\CategoryDeleteForm" * } * }, - * uri_callback = "contact_category_uri", * config_prefix = "contact.category", * bundle_of = "contact_message", * entity_keys = { * "id" = "id", * "label" = "label", * "uuid" = "uuid" + * }, + * links = { + * "edit-form" = "admin/structure/contact/manage/{contact_category}" * } * ) */ diff --git a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php index 71ca04d..a01e94a 100644 --- a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php @@ -38,6 +38,9 @@ * "uuid" = "uuid", * "weight" = "weight", * "status" = "status" + * }, + * links = { + * "edit-form" = "admin/config/content/formats/manage/{filter_format}" * } * ) */ @@ -191,19 +194,6 @@ public function disable() { /** * {@inheritdoc} */ - public function uri() { - return array( - 'path' => 'admin/config/content/formats/manage/' . $this->id(), - 'options' => array( - 'entity_type' => $this->entityType, - 'entity' => $this, - ), - ); - } - - /** - * {@inheritdoc} - */ public function preSave(EntityStorageControllerInterface $storage_controller) { $this->name = trim($this->label()); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index fa03dcd..c620ed4 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -78,15 +78,6 @@ function image_help($path, $arg) { } /** - * Entity URI callback for image style. - */ -function image_style_entity_uri(ImageStyle $style) { - return array( - 'path' => 'admin/config/media/image-styles/manage/' . $style->id(), - ); -} - -/** * Implements hook_menu(). */ function image_menu() { diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index 4d12539..b340bcd 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -35,12 +35,14 @@ * "list" = "Drupal\image\ImageStyleListController", * "access" = "Drupal\image\ImageStyleAccessController" * }, - * uri_callback = "image_style_entity_uri", * config_prefix = "image.style", * entity_keys = { * "id" = "name", * "label" = "label", * "uuid" = "uuid" + * }, + * links = { + * "edit-form" = "admin/config/media/image-styles/manage/{image_style}" * } * ) */ diff --git a/core/modules/language/lib/Drupal/language/Entity/Language.php b/core/modules/language/lib/Drupal/language/Entity/Language.php index 23f65db..c689361 100644 --- a/core/modules/language/lib/Drupal/language/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php @@ -35,6 +35,9 @@ * "label" = "label", * "weight" = "weight", * "uuid" = "uuid" + * }, + * links = { + * "edit-form" = "admin/config/regional/language/edit/{language_entity}" * } * ) */ @@ -95,17 +98,4 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { $this->langcode = 'en'; } - /** - * {@inheritdoc} - */ - public function uri() { - return array( - 'path' => 'admin/config/regional/language/edit/' . $this->id(), - 'options' => array( - 'entity_type' => $this->entityType, - 'entity' => $this, - ), - ); - } - } diff --git a/core/modules/user/lib/Drupal/user/Entity/Role.php b/core/modules/user/lib/Drupal/user/Entity/Role.php index 8529e87..7ab545a 100644 --- a/core/modules/user/lib/Drupal/user/Entity/Role.php +++ b/core/modules/user/lib/Drupal/user/Entity/Role.php @@ -35,6 +35,9 @@ * "uuid" = "uuid", * "weight" = "weight", * "label" = "label" + * }, + * links = { + * "edit-form" = "admin/people/roles/manage/{user_role}" * } * ) */ @@ -78,19 +81,6 @@ class Role extends ConfigEntityBase implements RoleInterface { /** * {@inheritdoc} */ - public function uri() { - return array( - 'path' => 'admin/people/roles/manage/' . $this->id(), - 'options' => array( - 'entity_type' => $this->entityType, - 'entity' => $this, - ), - ); - } - - /** - * {@inheritdoc} - */ public function getPermissions() { return $this->permissions; } diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index 82f93c4..2629a75 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -33,6 +33,9 @@ * "label" = "label", * "uuid" = "uuid", * "status" = "status" + * }, + * links = { + * "edit-form" = "admin/structure/views/view/{view}" * } * ) */ @@ -135,19 +138,6 @@ public function getExecutable() { } /** - * Overrides Drupal\Core\Entity\EntityInterface::uri(). - */ - public function uri() { - return array( - 'path' => 'admin/structure/views/view/' . $this->id(), - 'options' => array( - 'entity_type' => $this->entityType, - 'entity' => $this, - ), - ); - } - - /** * Overrides Drupal\Core\Config\Entity\ConfigEntityBase::createDuplicate(). */ public function createDuplicate() {