diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 683ef53..38697a1 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -198,36 +198,38 @@ public function uri($rel = 'canonical') { 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; } /**