You are here

function ViewsSearchQuery::conditionReplaceString in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/src/ViewsSearchQuery.php \Drupal\search\ViewsSearchQuery::conditionReplaceString()

Replaces the original condition with a custom one from views recursively.

Parameters

string $search: The searched value.

string $replace: The value which replaces the search value.

array $condition: The query conditions array in which the string is replaced. This is an item from a \Drupal\Core\Database\Query\Condition::conditions array, which must have a 'field' element.

File

core/modules/search/src/ViewsSearchQuery.php, line 77
Contains \Drupal\search\ViewsSearchQuery.

Class

ViewsSearchQuery
Extends the core SearchQuery to be able to gets its protected values.

Namespace

Drupal\search

Code

function conditionReplaceString($search, $replace, &$condition) {
  if ($condition['field'] instanceof Condition) {
    $conditions =& $condition['field']
      ->conditions();
    foreach ($conditions as $key => &$subcondition) {
      if (is_numeric($key)) {

        // As conditions can have subconditions, for example db_or(), the
        // function has to be called recursively.
        $this
          ->conditionReplaceString($search, $replace, $subcondition);
      }
    }
  }
  else {
    $condition['field'] = str_replace($search, $replace, $condition['field']);
  }
}