You are here

function _views_query_tag_alter_condition in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 8.3 views.module \_views_query_tag_alter_condition()

Replaces the substitutions recursive foreach condition.

1 call to _views_query_tag_alter_condition()
views_query_views_alter in ./views.module
Implements hook_query_TAG_alter().

File

./views.module, line 2418
Primarily Drupal hooks and global API functions to manipulate views.

Code

function _views_query_tag_alter_condition(QueryAlterableInterface $query, &$conditions, $substitutions) {
  foreach ($conditions as $condition_id => &$condition) {
    if (is_numeric($condition_id)) {
      if (is_string($condition['field'])) {
        $condition['field'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['field']);
      }
      elseif (is_object($condition['field'])) {
        $sub_conditions =& $condition['field']
          ->conditions();
        _views_query_tag_alter_condition($query, $sub_conditions, $substitutions);
      }

      // $condition['value'] is a subquery so alter the subquery recursive.
      // Therefore take sure to get the metadata of the main query.
      if (is_object($condition['value'])) {
        $subquery = $condition['value'];
        $subquery
          ->addMetaData('views_substitutions', $query
          ->getMetaData('views_substitutions'));
        views_query_views_alter($condition['value']);
      }
      elseif (isset($condition['value'])) {

        // Arrays need to be handled differently to strings as they could be
        // nested.
        if (is_array($condition['value'])) {

          // Use the callback to walk through the value, performing the search-
          // replace operation recursively.
          array_walk_recursive($condition['value'], '_views_str_replace_recursive', array(
            array_keys($substitutions),
            array_values($substitutions),
          ));
        }
        else {
          $condition['value'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['value']);
        }
      }
    }
  }
}