You are here

function lingotek_entity_load in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lingotek.module \lingotek_entity_load()
  2. 7.5 lingotek.module \lingotek_entity_load()
  3. 7.6 lingotek.module \lingotek_entity_load()

Implements hook_entity_load().

4 calls to lingotek_entity_load()
lingotek_entitycache_load in ./lingotek.module
Implements hook_entitycache_load().
lingotek_entity_save in ./lingotek.module
lingotek_form_node_form_alter in ./lingotek.module
Implements hook_form_BASE_FORM_ID_alter().
lingotek_grid_get_rows in ./lingotek.bulk_grid.inc
Dynamic query processing function for the grid Since the header defines which columns are shown, this query gets all possible values and refines the header using the columns selected in the UI The filters are also processed here

File

./lingotek.module, line 1538

Code

function lingotek_entity_load($entities, $entity_type) {
  if (empty($entities)) {
    return;
  }
  $default_special_entities = array(
    'field_collection_item',
    'message_type',
    'taxonomy_term',
    'bean',
  );
  $special_entities = variable_get('lingotek_special_entity_types', $default_special_entities);
  if (in_array($entity_type, $special_entities)) {
    foreach ($entities as $e) {
      lingotek_normalize_special_field_language($entity_type, $e);
    }
  }

  // Check for callbacks and cron jobs, otherwise return
  $is_anonymous = user_is_anonymous();
  $dest_url = drupal_get_destination();
  $dest_str = $dest_url['destination'];
  $is_cron = FALSE;
  $is_cron_var = FALSE;
  $is_lingotek = FALSE;
  $is_admin_url = FALSE;
  $is_drush = FALSE;
  $is_entitycache_enabled = FALSE;
  $has_permissions = user_access('administer lingotek') || user_access('manage projects') || user_access('translation') || user_access('use lingotek developer tools') ? TRUE : FALSE;
  global $locks;
  if ($is_anonymous) {
    if (isset($locks['cron'])) {
      $is_cron_var = TRUE;
    }
    if (strpos($dest_str, 'cron') !== FALSE) {
      $is_cron = TRUE;
    }
    if (strpos($dest_str, 'lingotek') !== FALSE) {
      $is_lingotek = TRUE;
    }
    if (strpos($dest_str, 'admin') !== FALSE) {
      $is_admin_url = TRUE;
    }
    if (php_sapi_name() == "cli") {
      $is_drush = TRUE;
    }
    if (module_exists('entitycache')) {
      $is_entitycache_enabled = TRUE;
    }
  }
  if ($is_anonymous && !$is_cron && !$is_lingotek && !$is_admin_url && !$is_cron_var && !$has_permissions && !$is_drush && !$is_entitycache_enabled) {
    return;
  }
  $query = db_select('lingotek_entity_metadata', 'l')
    ->fields('l', array(
    'entity_id',
    'entity_key',
    'value',
  ))
    ->condition('l.entity_id', array_keys($entities), 'IN')
    ->condition('l.entity_type', $entity_type)
    ->condition('l.entity_key', 'target_%', 'NOT LIKE');
  $result = $query
    ->execute();
  $values = array();
  foreach ($result as $record) {
    $values[$record->entity_id][$record->entity_key] = $record->value;
  }
  foreach ($entities as &$entity) {

    // Pull profile values for the entity
    list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);
    if (isset($values[$id]['profile'])) {

      // Load the profile directly if we already know the profile ID.
      $entity_profile = LingotekProfile::loadById($values[$id]['profile']);
    }
    else {
      $entity_profile = LingotekProfile::loadByEntity($entity_type, $entity);
    }
    $entity->lingotek = $entity_profile
      ->getAttributes();
    $entity->lingotek['profile'] = $entity_profile
      ->getId();

    // Overlay node-specific values (like doc ID, status, etc.) onto the entity
    if (!empty($values[$id])) {
      $entity->lingotek = array_merge($entity->lingotek, $values[$id]);
    }
  }
}