You are here

function ViewsSearchQuery::condition_replace_string in Views (for Drupal 7) 8.3

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.

Drupal\Core\Database\Query\Condition $condition: The query condition in which the string is replaced.

File

lib/Views/search/ViewsSearchQuery.php, line 68
Definition of Views\search\ViewsSearchQuery.

Class

ViewsSearchQuery
Extends the core SearchQuery to be able to gets it's protected values.

Namespace

Views\search

Code

function condition_replace_string($search, $replace, &$condition) {
  if ($condition['field'] instanceof DatabaseCondition) {
    $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
          ->condition_replace_string($search, $replace, $subcondition);
      }
    }
  }
  else {
    $condition['field'] = str_replace($search, $replace, $condition['field']);
  }
}