You are here

function lingotek_node_load in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.3 lingotek.module \lingotek_node_load()

Implements hook_node_load().

3 calls to lingotek_node_load()
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
lingotek_node_save in ./lingotek.module

File

./lingotek.module, line 1195

Code

function lingotek_node_load($nodes, $types) {
  if (empty($nodes)) {
    return;
  }
  $global_profile = lingotek_get_global_profile();
  $node_profile_defaults = lingotek_load_profile_defaults('node');

  // return assoc array by node type
  $profiles_list = lingotek_get_profiles();
  $result = db_select('lingotek', 'n')
    ->fields('n', array(
    'nid',
    'lingokey',
    'lingovalue',
  ))
    ->condition('n.nid', array_keys($nodes), 'IN')
    ->condition('n.lingokey', 'target_%', 'NOT LIKE')
    ->execute();
  $node_lingovalues = array();
  foreach ($result as $record) {
    $node_lingovalues[$record->nid][$record->lingokey] = $record->lingovalue;
  }
  foreach ($nodes as &$node) {

    //    if (!lingotek_supported_type($node->type)) {
    //      continue;
    //    }
    // translate node titles for workbench moderation 'View draft' node tab
    if (module_exists('workbench_moderation') && isset($node->workbench_moderation['published']) && $node->workbench_moderation['published']->vid != $node->vid) {

      // Workbench Moderation calls two node saves if viewing a draft, so we have to
      // clear this cache in order for the translated title fields to be loaded
      drupal_static_reset('title_entity_sync');
      title_entity_sync('node', $node);
    }

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

    // Step 2: add default profiles
    if (array_key_exists($node->type, $node_profile_defaults)) {
      $node->lingotek = array_merge($node->lingotek, $node_profile_defaults[$node->type]);
    }

    // Step 3: add node-specific profile
    if (isset($node->nid) && isset($node_lingovalues[$node->nid]['profile']) && is_numeric($node_lingovalues[$node->nid]['profile'])) {
      $node->lingotek = array_merge($node->lingotek, $profiles_list[$node_lingovalues[$node->nid]['profile']]);
    }

    // Step 4: add node-specific overrides
    if (isset($node->nid) && isset($node_lingovalues[$node->nid])) {
      $node->lingotek = array_merge($node->lingotek, $node_lingovalues[$node->nid]);
    }

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