You are here

function translation_views_query_views_alter in Translation Views 8

Implements hook_query_TAG_alter().

Add support to use views query substitutions in expressions from hook_views_query_substitutions(). Expressions can be used in views fields (i.e addField()), and views orderBy formula (i.e addOrderBy()).

@todo Remove this workaround when will be solved in drupal core.

File

./translation_views.module, line 94
Provide hooks for translation_views module.

Code

function translation_views_query_views_alter(AlterableInterface $query) {
  $substitutions = $query
    ->getMetaData('views_substitutions');
  $expressions =& $query
    ->getExpressions();
  foreach ($expressions as $field_id => &$item) {
    foreach ($item['arguments'] as $replacement_key => $value) {
      if (!is_array($value)) {
        if (isset($substitutions[$value])) {
          $expressions[$field_id]['arguments'][$replacement_key] = $substitutions[$value];
        }
      }
      else {
        foreach ($value as $sub_key => $sub_value) {
          if (isset($substitutions[$sub_value])) {
            $expressions[$field_id]['arguments'][$replacement_key][$sub_key] = $substitutions[$sub_value];
          }
        }
      }
    }
  }
}