You are here

function lingotek_entity_load in Lingotek Translation 7.5

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

Implements hook_entity_load().

3 calls to lingotek_entity_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 1318

Code

function lingotek_entity_load($entities, $entity_type) {
  if (empty($entities)) {
    return;
  }
  $special_entities = array(
    'field_collection_item',
    'message_type',
    'taxonomy_term',
  );
  if (in_array($entity_type, $special_entities)) {
    foreach ($entities as $e) {
      lingotek_normalize_special_field_language($entity_type, $e);
    }
  }
  $global_profile = lingotek_get_global_profile();
  $node_profile_defaults = lingotek_load_profile_defaults($entity_type);

  // return assoc array by node type
  $profiles_list = lingotek_get_profiles();
  $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) {

    //    if (!lingotek_supported_type($entity->type)) {
    //      continue;
    //    }
    list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);

    // Node profile inheritance heirarchy
    // Step 1: get global profile
    $entity->lingotek = $global_profile;

    // Step 2a: add entity-specific profile, if it exists
    if ($id && isset($values[$id]['profile']) && is_numeric($values[$id]['profile'])) {
      $entity->lingotek = array_merge($entity->lingotek, $profiles_list[$values[$id]['profile']]);
    }
    elseif (array_key_exists($bundle, $node_profile_defaults)) {
      $entity->lingotek = array_merge($entity->lingotek, $node_profile_defaults[$bundle]);
    }

    // Step 3: add node-specific overrides
    if ($id && isset($values[$id])) {
      $entity->lingotek = array_merge($entity->lingotek, $values[$id]);
    }

    // Step 4: if no profile, then disabled.
    if (!isset($entity->lingotek['profile']) || !strlen($entity->lingotek['profile'])) {
      $entity->lingotek['profile'] = LingotekSync::PROFILE_DISABLED;
    }
  }
}