Skip to content
Snippets Groups Projects
Commit 24dca837 authored by Daniel Wehner's avatar Daniel Wehner Committed by Tim Plunkett
Browse files

Issue #1760748 by dawehner, aspilicious: Move ViewsSearchQuery.

parent 336e2e10
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php <?php
/**
* @file
* Definition of Drupal\views\Search\ViewsSearchQuery.
*/
namespace Drupal\search; namespace Drupal\search;
/** /**
* Extends the core SearchQuery. * Extends the core SearchQuery to be able to gets it's protected values.
*
* @todo: Make this class PSR-0 compatible.
*/ */
class ViewsSearchQuery extends SearchQuery { class ViewsSearchQuery extends SearchQuery {
/**
* Returns the conditions property.
*
* @return array
*/
public function &conditions() { public function &conditions() {
return $this->conditions; return $this->conditions;
} }
/**
* Returns the words property.
*
* @return array
*/
public function words() { public function words() {
return $this->words; return $this->words;
} }
/**
* Returns the simple property.
*
* @return bool
*/
public function simple() { public function simple() {
return $this->simple; return $this->simple;
} }
/**
* Returns the matches property.
*
* @return int
*/
public function matches() { public function matches() {
return $this->matches; return $this->matches;
} }
/**
* Executes and returns the protected parseSearchExpression method.
*/
public function publicParseSearchExpression() { public function publicParseSearchExpression() {
return $this->parseSearchExpression(); return $this->parseSearchExpression();
} }
/**
* Replaces the original condition with a custom one from views recursively.
*
* @param string $search
* The searched value.
* @param string $replace
* The value which replaces the search value.
* @param Drupal\Core\Database\Query\Condition $condition
* The query condition in which the string is replaced.
*/
function condition_replace_string($search, $replace, &$condition) { function condition_replace_string($search, $replace, &$condition) {
if ($condition['field'] instanceof DatabaseCondition) { if ($condition['field'] instanceof DatabaseCondition) {
$conditions =& $condition['field']->conditions(); $conditions =& $condition['field']->conditions();
foreach ($conditions as $key => &$subcondition) { foreach ($conditions as $key => &$subcondition) {
if (is_numeric($key)) { 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); $this->condition_replace_string($search, $replace, $subcondition);
} }
} }
...@@ -40,4 +80,5 @@ function condition_replace_string($search, $replace, &$condition) { ...@@ -40,4 +80,5 @@ function condition_replace_string($search, $replace, &$condition) {
$condition['field'] = str_replace($search, $replace, $condition['field']); $condition['field'] = str_replace($search, $replace, $condition['field']);
} }
} }
} }
...@@ -30,7 +30,7 @@ class Search extends ArgumentPluginBase { ...@@ -30,7 +30,7 @@ class Search extends ArgumentPluginBase {
*/ */
function query_parse_search_expression($input) { function query_parse_search_expression($input) {
if (!isset($this->search_query)) { if (!isset($this->search_query)) {
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('viewsSearchQuery'); $this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\views\Search\ViewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table); $this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression(); $this->search_query->publicParseSearchExpression();
} }
......
...@@ -26,9 +26,12 @@ class Search extends FilterPluginBase { ...@@ -26,9 +26,12 @@ class Search extends FilterPluginBase {
var $always_multiple = TRUE; var $always_multiple = TRUE;
/** /**
* Stores a viewsSearchQuery object to be able to use the search.module "api". * Stores an extended query extender from the search module.
* *
* @var viewsSearchQuery * This value extends the query extender to be able to provide methods
* which returns the protected values.
*
* @var Drupal\views\Search\ViewsSearchQuery
*/ */
var $search_query = NULL; var $search_query = NULL;
...@@ -99,7 +102,7 @@ function exposed_validate(&$form, &$form_state) { ...@@ -99,7 +102,7 @@ function exposed_validate(&$form, &$form_state) {
function query_parse_search_expression($input) { function query_parse_search_expression($input) {
if (!isset($this->search_query)) { if (!isset($this->search_query)) {
$this->parsed = TRUE; $this->parsed = TRUE;
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\search\ViewsSearchQuery'); $this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\views\Search\ViewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table); $this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression(); $this->search_query->publicParseSearchExpression();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment