diff --git a/core/modules/search/lib/Drupal/search/Routing/SearchController.php b/core/modules/search/lib/Drupal/search/Routing/SearchController.php index acdb255..bbe6391 100644 --- a/core/modules/search/lib/Drupal/search/Routing/SearchController.php +++ b/core/modules/search/lib/Drupal/search/Routing/SearchController.php @@ -9,6 +9,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; class SearchController { @@ -19,17 +20,20 @@ class SearchController { * Search module to use for the search. * @param string $keys * Keywords to use for the search. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. * * @return array * An array as expected by drupal_render(). */ - public function searchView($module, $keys) { + public function searchView($module, $keys, Request $request) { $info = FALSE; $keys = trim($keys); // Also try to pull search keywords out of the $_REQUEST variable to // support old GET format of searches for existing links. - if (!$keys && !empty($_REQUEST['keys'])) { - $keys = trim($_REQUEST['keys']); + $request_keys = $request->request->get('keys'); + if (!$keys && !empty($request_keys)) { + $keys = trim($request_keys); } if (!empty($module)) { @@ -44,7 +48,8 @@ public function searchView($module, $keys) { // are no enabled search modules, this function should never be called, // since hook_menu() would not have defined any search paths. $info = search_get_default_module_info(); - // Redirect from bare /search or an invalid path to the default search path. + // Redirect from bare /search or an invalid path to the default search + // path. $path = 'search/' . $info['path']; if ($keys) { $path .= '/' . $keys; @@ -55,12 +60,13 @@ public function searchView($module, $keys) { // Default results output is an empty string. $results = array('#markup' => ''); // Process the search form. Note that if there is $_POST data, - // search_form_submit() will cause a redirect to search/[module path]/[keys], - // which will get us back to this page callback. In other words, the search - // form submits with POST but redirects to GET. This way we can keep - // the search query URL clean as a whistle. - if (empty($_POST['form_id']) || $_POST['form_id'] != 'search_form') { - $conditions = NULL; + // search_form_submit() will cause a redirect to + // search/[module path]/[keys], which will get us back to this page + // callback. In other words, the search form submits with POST but redirects + // to GET. This way we can keep the search query URL clean as a whistle. + $form_id = $request->request->get('form_id'); + if (empty($form_id) || $form_id != 'search_form') { + $conditions = NULL; if (isset($info['conditions_callback'])) { // Build an optional array of more search conditions. $conditions = call_user_func($info['conditions_callback'], $keys); @@ -74,6 +80,10 @@ public function searchView($module, $keys) { $results = search_data($keys, $info['module'], $conditions); } } + + // @todo Refactor this once search form is converted to form interface. + \Drupal::moduleHandler()->loadInclude('search', 'inc', 'search.pages'); + // The form may be altered based on whether the search was run. $build['search_form'] = drupal_get_form('search_form', NULL, $keys, $info['module']); $build['search_results'] = $results; diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index e722021..d9455b6 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -6,18 +6,6 @@ */ /** - * Page callback: Presents the search form and/or search results. - * - * @param $module - * Search module to use for the search. - * @param $keys - * Keywords to use for the search. - */ -function search_view($module = NULL, $keys = '') { - -} - -/** * Prepares variables for search results templates. * * Default template: search-results.html.twig. diff --git a/core/modules/search/search.routing.yml b/core/modules/search/search.routing.yml index 07661bd..620df25 100644 --- a/core/modules/search/search.routing.yml +++ b/core/modules/search/search.routing.yml @@ -7,6 +7,7 @@ search_reindex_confirm: search_view: pattern: '/search/{module}/{keys}' + method: [GET,POST] defaults: _content: 'Drupal\search\Routing\SearchController::searchView' module: ~