diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index cc7b316..0664748 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -153,11 +153,7 @@ public function urlInfo($rel = 'canonical') { // The links array might contain URI templates set in annotations. $link_templates = $this->linkTemplates(); - if (isset($link_templates[$rel])) { - // If there is a template for the given relationship type, generate the path. - $uri = new Url($link_templates[$rel], $this->urlRouteParameters($rel)); - } - else { + if ($this->getEntityType()->hasKey('bundle')) { $bundle = $this->bundle(); // A bundle-specific callback takes precedence over the generic one for // the entity type. @@ -165,21 +161,29 @@ public function urlInfo($rel = 'canonical') { if (isset($bundles[$bundle]['uri_callback'])) { $uri_callback = $bundles[$bundle]['uri_callback']; } - elseif ($entity_uri_callback = $this->getEntityType()->getUriCallback()) { + } + + if (!isset($uri_callback)) { + // If there is no bundle callback, use the default URI format. + if ($entity_uri_callback = $this->getEntityType()->getUriCallback()) { $uri_callback = $entity_uri_callback; } + } - // Invoke the callback to get the URI. If there is no callback, use the - // default URI format. - if (isset($uri_callback) && is_callable($uri_callback)) { - $uri = call_user_func($uri_callback, $this); - } - else { - throw new UndefinedLinkTemplateException(String::format('No link template "@rel" found for the "@entity_type" entity type', array( - '@rel' => $rel, - '@entity_type' => $this->getEntityTypeId(), - ))); - } + if (isset($uri_callback) && is_callable($uri_callback)) { + // Invoke the callback to get the URI. + $uri = call_user_func($uri_callback, $this); + } + elseif (isset($link_templates[$rel])) { + // If there is a template for the given relationship type, generate the + // path. + $uri = new Url($link_templates[$rel], $this->urlRouteParameters($rel)); + } + else { + throw new UndefinedLinkTemplateException(String::format('No link template "@rel" found for the "@entity_type" entity type', array( + '@rel' => $rel, + '@entity_type' => $this->getEntityTypeId(), + ))); } // Pass the entity data to url() so that alter functions do not need to diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 435cbe6..4b30b69 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -34,7 +34,6 @@ * "translation" = "Drupal\taxonomy\TermTranslationHandler" * }, * base_table = "taxonomy_term_data", - * uri_callback = "taxonomy_term_uri", * fieldable = TRUE, * translatable = TRUE, * entity_keys = { diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index fde291e..c337529 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -116,15 +116,6 @@ function taxonomy_permission() { } /** - * Entity URI callback. - */ -function taxonomy_term_uri($term) { - return new Url('taxonomy.term_page', array( - 'taxonomy_term' => $term->id(), - )); -} - -/** * Return nodes attached to a term across all field instances. * * This function requires taxonomy module to be maintaining its own tables,