1 path.module path_load_multiple_by_entities(array $entities)

Populate the path properties for multiple entities.

Parameters

array $entities: An array of entities (nodes/users/terms/etc.) keyed by the entity ID, for which each path should be loaded.

File

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

Code

function path_load_multiple_by_entities(array $entities) {
  $sources = array();
  $map = array();

  // Each entity may have a different language, so group them by langcode.
  foreach ($entities as $entity) {
    $uri = $entity->uri();
    if (!empty($uri)) {
      $langcode = isset($entity->langcode) ? $entity->langcode : LANGUAGE_NONE;
      $sources[$langcode][] = $uri['path'];
      $map[$langcode][$uri['path']] = $entity->id();

      // Provide a default path in the event no path is found.
      $entity->path = array(
        'pid' => NULL,
        'source' => $uri['path'],
        'alias' => NULL,
        'langcode' => $langcode,
        'auto' => FALSE,
      );
    }
  }

  // Load each set of paths by langcode, and update each entity's path property.
  foreach ($sources as $langcode => $entity_ids) {
    $paths = path_load_multiple($entity_ids, 'source', $langcode);
    foreach ($paths as $source => $path) {
      $entity_id = $map[$langcode][$source];
      $entities[$entity_id]->path = $path;
    }
  }
}