diff --git a/core/modules/search/lib/Drupal/search/Access/SearchCheck.php b/core/modules/search/lib/Drupal/search/Access/SearchCheck.php new file mode 100644 index 0000000..aa43304 --- /dev/null +++ b/core/modules/search/lib/Drupal/search/Access/SearchCheck.php @@ -0,0 +1,36 @@ +getRequirements()); + } + + /** + * {@inheritdoc} + */ + public function access(Route $route, Request $request) { + return user_access('search content') && search_get_info(); + } + +} diff --git a/core/modules/search/lib/Drupal/search/Routing/SearchController.php b/core/modules/search/lib/Drupal/search/Routing/SearchController.php new file mode 100644 index 0000000..714359c --- /dev/null +++ b/core/modules/search/lib/Drupal/search/Routing/SearchController.php @@ -0,0 +1,94 @@ + ''); + // 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; + if (isset($info['conditions_callback'])) { + // Build an optional array of more search conditions. + $conditions = call_user_func($info['conditions_callback'], $keys); + } + // Only search if there are keywords or non-empty conditions. + if ($keys || !empty($conditions)) { + // Log the search keys. + watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $info['path'] . '/' . $keys)); + + // Collect the search results. + $results = search_data($keys, $info['module'], $conditions); + } + } + // 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; + + return $build; + } +} diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 6501a85..e81e502 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -150,10 +150,8 @@ function search_preprocess_block(&$variables) { function search_menu() { $items['search'] = array( 'title' => 'Search', - 'page callback' => 'search_view', - 'access callback' => 'search_is_active', 'type' => MENU_SUGGESTED_ITEM, - 'file' => 'search.pages.inc', + 'route_name' => 'search_view', ); $items['admin/config/search/settings'] = array( 'title' => 'Search settings', diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index eaae71a..e722021 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -14,61 +14,7 @@ * Keywords to use for the search. */ function search_view($module = NULL, $keys = '') { - $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']); - } - - if (!empty($module)) { - $active_module_info = search_get_info(); - if (isset($active_module_info[$module])) { - $info = $active_module_info[$module]; - } - } - - if (empty($info)) { - // No path or invalid path: find the default module. Note that if there - // 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. - $path = 'search/' . $info['path']; - if ($keys) { - $path .= '/' . $keys; - } - drupal_goto($path); - } - - // 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; - if (isset($info['conditions_callback'])) { - // Build an optional array of more search conditions. - $conditions = call_user_func($info['conditions_callback'], $keys); - } - // Only search if there are keywords or non-empty conditions. - if ($keys || !empty($conditions)) { - // Log the search keys. - watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $info['path'] . '/' . $keys)); - - // Collect the search results. - $results = search_data($keys, $info['module'], $conditions); - } - } - // 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; - return $build; } /** diff --git a/core/modules/search/search.routing.yml b/core/modules/search/search.routing.yml index 5521e18..4012e7e 100644 --- a/core/modules/search/search.routing.yml +++ b/core/modules/search/search.routing.yml @@ -4,3 +4,10 @@ search_reindex_confirm: _form: 'Drupal\search\Form\ReindexConfirm' requirements: _permission: 'administer search' + +search_view: + pattern: 'search/{module}/{keys}' + defaults: + _controller: 'Drupal\search\Routing\SearchController::searchView' + requirements: + _search_view_access: 'TRUE' diff --git a/core/modules/search/search.services.yml b/core/modules/search/search.services.yml new file mode 100644 index 0000000..66a03df --- /dev/null +++ b/core/modules/search/search.services.yml @@ -0,0 +1,5 @@ +services: + access_check.search_view: + class: Drupal\search\Access\SearchCheck + tags: + - { name: access_check }