You are here

function pathauto_entity_load in Pathauto 7

Implements hook_entity_load().

2 string references to 'pathauto_entity_load'
pathauto_entity_state_delete in ./pathauto.module
Delete the pathauto state for an entity.
pathauto_entity_state_save in ./pathauto.module
Save the pathauto state for an entity.

File

./pathauto.module, line 344
Main file for the Pathauto module, which automatically generates aliases for content.

Code

function pathauto_entity_load($entities, $entity_type) {

  // Statically cache which entity types have data in the pathauto_state
  // table to avoid unnecessary queries for entities that would not have any
  // data anyway.
  static $loadable_types;
  if (!isset($loadable_types)) {
    $loadable_types =& drupal_static(__FUNCTION__);
    if (!isset($loadable_types)) {

      // Prevent errors if pathauto_update_7006() has not yet been run.
      if (!db_table_exists('pathauto_state')) {
        $loadable_types = array();
      }
      else {
        $loadable_types = db_query("SELECT DISTINCT entity_type FROM {pathauto_state}")
          ->fetchCol();
      }
    }
  }

  // Check if this entity type has loadable records.
  if (!in_array($entity_type, $loadable_types)) {
    return;
  }
  $states = pathauto_entity_state_load_multiple($entity_type, array_keys($entities));
  foreach ($states as $id => $state) {
    if (!isset($entities[$id]->path)) {
      $entities[$id]->path = array();
    }
    if (is_array($entities[$id]->path) && !isset($entities[$id]->path['pathauto'])) {
      $entities[$id]->path['pathauto'] = $state;
    }
  }
}