function views_query_views_alter

Same name in other branches
  1. 9 core/modules/views/views.module \views_query_views_alter()
  2. 10 core/modules/views/views.module \views_query_views_alter()
  3. 11.x core/modules/views/views.module \views_query_views_alter()

Implements hook_query_TAG_alter().

This is the hook_query_alter() for queries tagged by Views and is used to add in substitutions from hook_views_query_substitutions().

1 call to views_query_views_alter()
_views_query_tag_alter_condition in core/modules/views/views.module
Replaces the substitutions recursive foreach condition.

File

core/modules/views/views.module, line 660

Code

function views_query_views_alter(AlterableInterface $query) {
    $substitutions = $query->getMetaData('views_substitutions');
    $tables =& $query->getTables();
    $where =& $query->conditions();
    // Replaces substitutions in tables.
    foreach ($tables as $table_name => $table_metadata) {
        foreach ($table_metadata['arguments'] as $replacement_key => $value) {
            if (!is_array($value)) {
                if (isset($substitutions[$value])) {
                    $tables[$table_name]['arguments'][$replacement_key] = $substitutions[$value];
                }
            }
            else {
                foreach ($value as $sub_key => $sub_value) {
                    if (isset($substitutions[$sub_value])) {
                        $tables[$table_name]['arguments'][$replacement_key][$sub_key] = $substitutions[$sub_value];
                    }
                }
            }
        }
    }
    // Replaces substitutions in filter criteria.
    _views_query_tag_alter_condition($query, $where, $substitutions);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.