You are here

function entity_uri in Drupal 7

Returns the URI elements of an entity.

Parameters

$entity_type: The entity type; e.g. 'node' or 'user'.

$entity: The entity for which to generate a path.

Return value

An array containing the 'path' and 'options' keys used to build the URI of the entity, and matching the signature of url(). NULL if the entity has no URI of its own.

13 calls to entity_uri()
image_field_formatter_view in modules/image/image.field.inc
Implements hook_field_formatter_view().
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
node_page_view in modules/node/node.module
Menu callback: Displays a single node.
node_search_execute in modules/node/node.module
Implements hook_search_execute().
rdf_preprocess_comment in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().

... See full list

File

includes/common.inc, line 8275
Common functions that many Drupal modules will need to reference.

Code

function entity_uri($entity_type, $entity) {
  $info = entity_get_info($entity_type);
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // A bundle-specific callback takes precedence over the generic one for the
  // entity type.
  if (isset($info['bundles'][$bundle]['uri callback'])) {
    $uri_callback = $info['bundles'][$bundle]['uri callback'];
  }
  elseif (isset($info['uri callback'])) {
    $uri_callback = $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($entity);

    // Pass the entity data to url() so that alter functions do not need to
    // lookup this entity again.
    $uri['options']['entity_type'] = $entity_type;
    $uri['options']['entity'] = $entity;
    return $uri;
  }
}