function ViewsSearchQuery::conditionReplaceString

Same name in other branches
  1. 9 core/modules/search/src/ViewsSearchQuery.php \Drupal\search\ViewsSearchQuery::conditionReplaceString()
  2. 8.9.x core/modules/search/src/ViewsSearchQuery.php \Drupal\search\ViewsSearchQuery::conditionReplaceString()
  3. 11.x 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 72

Class

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

Namespace

Drupal\search

Code

public function conditionReplaceString($search, $replace, &$condition) {
    if ($condition['field'] instanceof ConditionInterface) {
        $conditions =& $condition['field']->conditions();
        foreach ($conditions as $key => &$subcondition) {
            if (is_numeric($key)) {
                // As conditions can be nested, the function has to be called
                // recursively.
                $this->conditionReplaceString($search, $replace, $subcondition);
            }
        }
    }
    else {
        $condition['field'] = str_replace($search, $replace, $condition['field']);
    }
}

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