public function Entity::uri

Implements EntityInterface::uri().

Overrides EntityInterface::uri

1 method overrides Entity::uri()
View::uri in drupal/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php
Overrides Drupal\Core\Entity\EntityInterface::uri().

File

drupal/core/lib/Drupal/Core/Entity/Entity.php, line 151
Definition of Drupal\Core\Entity\Entity.

Class

Entity
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function uri() {
  $bundle = $this
    ->bundle();

  // A bundle-specific callback takes precedence over the generic one for the
  // entity type.
  $entity_info = $this
    ->entityInfo();
  if (isset($entity_info['bundles'][$bundle]['uri_callback'])) {
    $uri_callback = $entity_info['bundles'][$bundle]['uri_callback'];
  }
  elseif (isset($entity_info['uri_callback'])) {
    $uri_callback = $entity_info['uri_callback'];
  }
  else {
    return NULL;
  }

  // Invoke the callback to get the URI. If there is no callback, return NULL.
  if (isset($uri_callback) && function_exists($uri_callback)) {
    $uri = $uri_callback($this);

    // 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;
  }
}