ViewsSearchQuery::conditionReplaceString

ViewsSearchQuery::conditionReplaceString($search, $replace, &$condition)

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

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']);
  }
}
doc_Drupal
2016-10-29 09:55:31
Comments
Leave a Comment

Please login to continue.