summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-09-27 22:10:24 (GMT)
committerwebchick2013-09-27 22:10:24 (GMT)
commit5fccca655e90d9e7a557fda8d16dc2afab93ac08 (patch)
tree60bc31c62368b190385d9bba853364ba1424e851
parent753a5485c9f49c01fea848884034d555b5983727 (diff)
Issue #2083615 by Gábor Hojtsy, YesCT, tim.plunkett, Schnitzel: Use links annotation for config entity URI like for content entities.
-rw-r--r--core/lib/Drupal/Core/Entity/Entity.php61
-rw-r--r--core/modules/action/action.module1
-rw-r--r--core/modules/menu/menu.module14
-rw-r--r--core/modules/system/lib/Drupal/system/Entity/Action.php3
-rw-r--r--core/modules/system/lib/Drupal/system/Entity/Menu.php3
5 files changed, 34 insertions, 48 deletions
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 6d41d13..fd1dc38 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -163,8 +163,9 @@ class Entity implements \IteratorAggregate, EntityInterface {
* @code
* uri_callback = "contact_category_uri",
* @endcode
- * If looking for the canonical URI, and it was not set in the links array
- * or in a uri_callback function, the path is set using the default template:
+ * If the path is not set in the links array, the uri_callback function is
+ * used for setting the path. If this does not exist and the link relationship
+ * type is canonical, the path is set using the default template:
* entity/entityType/id.
*
* @param string $rel
@@ -198,36 +199,38 @@ class Entity implements \IteratorAggregate, EntityInterface {
return $uri;
}
+ $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);
+ }
// Only use these defaults for a canonical link (that is, a link to self).
// 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;
+ elseif ($rel == 'canonical') {
+ $uri = array(
+ 'path' => 'entity/' . $this->entityType . '/' . $this->id(),
+ );
+ }
+ else {
+ return array();
}
+
+ // 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;
}
/**
diff --git a/core/modules/action/action.module b/core/modules/action/action.module
index 5c0e350..4dc9a3b 100644
--- a/core/modules/action/action.module
+++ b/core/modules/action/action.module
@@ -84,4 +84,5 @@ function action_entity_info(&$entity_info) {
$entity_info['action']['controllers']['form']['edit'] = 'Drupal\action\ActionEditFormController';
$entity_info['action']['controllers']['form']['delete'] = 'Drupal\action\Form\ActionDeleteForm';
$entity_info['action']['controllers']['list'] = 'Drupal\action\ActionListController';
+ $entity_info['action']['links']['edit-form'] = 'admin/config/system/actions/configure/{action}';
}
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index 1689d35..70cf6e6 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -121,7 +121,7 @@ function menu_menu() {
*/
function menu_entity_info(&$entity_info) {
$entity_info['menu']['controllers']['list'] = 'Drupal\menu\MenuListController';
- $entity_info['menu']['uri_callback'] = 'menu_uri';
+ $entity_info['menu']['links']['edit-form'] = 'admin/structure/menu/manage/{menu}';
$entity_info['menu']['controllers']['form'] = array(
'add' => 'Drupal\menu\MenuFormController',
'edit' => 'Drupal\menu\MenuFormController',
@@ -149,18 +149,6 @@ function menu_entity_bundle_info() {
}
/**
- * Entity URI callback.
- *
- * @param \Drupal\system\Entity\Menu $menu
- * A Menu entity.
- */
-function menu_uri(Menu $menu) {
- return array(
- 'path' => 'admin/structure/menu/manage/' . $menu->id(),
- );
-}
-
-/**
* Implements hook_theme().
*/
function menu_theme() {
diff --git a/core/modules/system/lib/Drupal/system/Entity/Action.php b/core/modules/system/lib/Drupal/system/Entity/Action.php
index ac73e40..ac68e3e 100644
--- a/core/modules/system/lib/Drupal/system/Entity/Action.php
+++ b/core/modules/system/lib/Drupal/system/Entity/Action.php
@@ -31,9 +31,6 @@ use Drupal\Component\Plugin\ConfigurablePluginInterface;
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
- * },
- * links = {
- * "edit-form" = "admin/config/system/actions/configure/{action}"
* }
* )
*/
diff --git a/core/modules/system/lib/Drupal/system/Entity/Menu.php b/core/modules/system/lib/Drupal/system/Entity/Menu.php
index 0898744..4727f8a 100644
--- a/core/modules/system/lib/Drupal/system/Entity/Menu.php
+++ b/core/modules/system/lib/Drupal/system/Entity/Menu.php
@@ -28,9 +28,6 @@ use Drupal\system\MenuInterface;
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
- * },
- * links = {
- * "edit-form" = "admin/structure/menu/manage/{menu}"
* }
* )
*/