public function ViewsSearchQuery::conditionReplaceString in Drupal 10
Same name and namespace in other branches
- 8 core/modules/search/src/ViewsSearchQuery.php \Drupal\search\ViewsSearchQuery::conditionReplaceString()
- 9 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\searchCode
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']);
}
}