1 path.module path_load_by_entity(Entity $entity)

Populate the canonical path property for an entity.

Parameters

Entity $entity: An entity (node/user/term/etc.) object for which the path should be loaded.

File

core/modules/path/path.module, line 661
Enables users to customize URLs and provide automatic URL alias patterns.

Code

function path_load_by_entity(Entity $entity) {
  $uri = $entity->uri();
  $langcode = isset($entity->langcode) ? $entity->langcode : LANGUAGE_NONE;
  $conditions = array(
    'source' => $uri['path'],
    'langcode' => $langcode,
  );
  $path = path_load($conditions);
  if ($path === FALSE) {
    // If no path is found, this is an unaliased entity that may specifically
    // have had its alias removed, so "auto" defaults to FALSE.
    $path = array(
      'pid' => NULL,
      'source' => $uri['path'],
      'alias' => NULL,
      'langcode' => $langcode,
      'auto' => FALSE,
    );
  }
  return $path;
}