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 b74c1d7..6b764b8 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/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/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/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/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() {