_views_query_tag_alter_condition

_views_query_tag_alter_condition(AlterableInterface $query, &$conditions, $substitutions)

Replaces the substitutions recursive foreach condition.

File

core/modules/views/views.module, line 676
Primarily Drupal hooks and global API functions to manipulate views.

Code

function _views_query_tag_alter_condition(AlterableInterface $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 make 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'])) {
        // We can not use a simple str_replace() here because it always returns
        // a string and we have to keep the type of the condition value intact.
        if (is_array($condition['value'])) {
          foreach ($condition['value'] as &$value) {
            if (is_string($value)) {
              $value = str_replace(array_keys($substitutions), array_values($substitutions), $value);
            }
          }
        }
        elseif (is_string($condition['value'])) {
          $condition['value'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['value']);
        }
      }
    }
  }
}
doc_Drupal
2016-10-29 09:57:24
Comments
Leave a Comment

Please login to continue.