diff --git a/core/modules/search/lib/Drupal/search/Controller/SearchController.php b/core/modules/search/lib/Drupal/search/Controller/SearchController.php index cc8dc00..5c3756b 100644 --- a/core/modules/search/lib/Drupal/search/Controller/SearchController.php +++ b/core/modules/search/lib/Drupal/search/Controller/SearchController.php @@ -24,7 +24,7 @@ class SearchController extends ControllerBase implements ContainerInjectionInter * * @var \Drupal\search\SearchPluginManager */ - protected $searchPluginManager; + protected $searchManager; /** * Constructs a new search controller. @@ -33,7 +33,7 @@ class SearchController extends ControllerBase implements ContainerInjectionInter * The search plugin manager. */ public function __construct(SearchPluginManager $search_plugin_manager) { - $this->searchPluginManager = $search_plugin_manager; + $this->searchManager = $search_plugin_manager; } /** @@ -45,13 +45,16 @@ public static function create(ContainerInterface $container) { /** * @param Request $request - * @param null $plugin_id - * @param null $keys + * @param int $plugin_id + * Plugin ID. + * @param string $keys + * search keywords. * * @return array + * Form Array * */ - public function searchView(Request $request, $plugin_id = NULL, $keys = NULL) { + public function view(Request $request, $plugin_id = NULL, $keys = NULL) { $info = FALSE; $keys = trim($keys); // Also try to pull search keywords out of the $_REQUEST variable to @@ -61,7 +64,7 @@ public function searchView(Request $request, $plugin_id = NULL, $keys = NULL) { } if (!empty($plugin_id)) { - $active_plugin_info = $this->searchPluginManager->getActiveDefinitions(); + $active_plugin_info = $this->searchManager->getActiveDefinitions(); if (isset($active_plugin_info[$plugin_id])) { $info = $active_plugin_info[$plugin_id]; } @@ -80,7 +83,7 @@ public function searchView(Request $request, $plugin_id = NULL, $keys = NULL) { } return new RedirectResponse(url($path, array('absolute' => TRUE))); } - $plugin = $this->searchPluginManager->createInstance($plugin_id); + $plugin = $this->searchManager->createInstance($plugin_id); $plugin->setSearch($keys, $request->query->all(), $request->attributes->all()); // Default results output is an empty string. $results = array('#markup' => ''); @@ -101,10 +104,11 @@ public function searchView(Request $request, $plugin_id = NULL, $keys = NULL) { } } // The form may be altered based on whether the search was run. - $build['search_form'] = drupal_get_form('search_form', $plugin); + $build['search_form'] = drupal_get_form(SearchForm::create($this->container), $plugin_id); $build['search_results'] = $results; return $build; } } + diff --git a/core/modules/search/lib/Drupal/search/Form/SearchForm.php b/core/modules/search/lib/Drupal/search/Form/SearchForm.php index fab4153..1d99847 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchForm.php @@ -1,17 +1,46 @@ get('plugin.manager.search') + ); + } + + /** + * Constructs a search form. + * + * @param Drupal\search\SearchPluginManager + * The search plugin manager. + * + */ + public function __construct(SearchInterface $search_plugin) { + $this->searchManager = $search_plugin; + + } /** * {@inheritdoc} @@ -23,8 +52,40 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, $plugin_id = NULL, $keys = NULL) { - } + public function buildForm(array $form, array &$form_state, $plugin_id = NULL) { + $plugin = $this->searchManager->createInstance($plugin_id); + $plugin_info = $plugin->getPluginDefinition(); + + if (!$action) { + $action = 'search/' . $plugin_info['path']; + } + if (!isset($prompt)) { + $prompt = $this->t('Enter your keywords'); + } + $form['#action'] = $this->getUrlGenerator()->generateFromPath($action); + // Record the $action for later use in redirecting. + $form_state['action'] = $action; + $form['plugin_id'] = array('#type' => 'value', '#value' => $plugin->getPluginId()); + $form['basic'] = array('#type' => 'container', '#attributes' => array('class' => array('container-inline'))); + $form['basic']['keys'] = array( + '#type' => 'search', + '#title' => $prompt, + '#default_value' => $plugin->getKeywords(), + '#size' => $prompt ? 40 : 20, + '#maxlength' => 255, + ); + // processed_keys is used to coordinate keyword passing between other forms + // that hook into the basic search form. + $form['basic']['processed_keys'] = array('#type' => 'value', '#value' => ''); + $form['basic']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search')); + // Make sure the default validate and submit handlers are added. + $form['#validate'][] = 'search_form_validate'; + $form['#submit'][] = 'search_form_submit'; + // Allow the plugin to add to or alter the search form. + $plugin->searchFormAlter($form, $form_state); + + return $form; + } } diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 5236efd..5b7e6de 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -658,60 +658,6 @@ function search_mark_for_reindex($type, $sid) { */ /** - * Form constructor for the search form. - * - * @param \Drupal\search\Plugin\SearchInterface $plugin - * A search plugin instance to render the form for. - * @param $action - * Form action. Defaults to "search/$path", where $path is the search path - * associated with the plugin in its definition. This will be run through - * url(). - * @param $prompt - * Label for the keywords field. Defaults to t('Enter your keywords') if - * NULL. Supply '' to omit. - * - * @see search_form_validate() - * @see search_form_submit() - * - * @ingroup forms - */ -function search_form($form, &$form_state, SearchInterface $plugin, $action = '', $prompt = NULL) { - - $plugin_info = $plugin->getPluginDefinition(); - - if (!$action) { - $action = 'search/' . $plugin_info['path']; - } - if (!isset($prompt)) { - $prompt = t('Enter your keywords'); - } - - $form['#action'] = url($action); - // Record the $action for later use in redirecting. - $form_state['action'] = $action; - $form['plugin_id'] = array('#type' => 'value', '#value' => $plugin->getPluginId()); - $form['basic'] = array('#type' => 'container', '#attributes' => array('class' => array('container-inline'))); - $form['basic']['keys'] = array( - '#type' => 'search', - '#title' => $prompt, - '#default_value' => $plugin->getKeywords(), - '#size' => $prompt ? 40 : 20, - '#maxlength' => 255, - ); - // processed_keys is used to coordinate keyword passing between other forms - // that hook into the basic search form. - $form['basic']['processed_keys'] = array('#type' => 'value', '#value' => ''); - $form['basic']['submit'] = array('#type' => 'submit', '#value' => t('Search')); - // Make sure the default validate and submit handlers are added. - $form['#validate'][] = 'search_form_validate'; - $form['#submit'][] = 'search_form_submit'; - // Allow the plugin to add to or alter the search form. - $plugin->searchFormAlter($form, $form_state); - - return $form; -} - -/** * Form constructor for the search block's search box. * * @param $form_id diff --git a/core/modules/search/search.routing.yml b/core/modules/search/search.routing.yml index 7120b5a..707ddca 100644 --- a/core/modules/search/search.routing.yml +++ b/core/modules/search/search.routing.yml @@ -1,20 +1,21 @@ search_settings: pattern: '/admin/config/search/settings' defaults: - _form: 'Drupal\search\Form\SearchSettingsForm' + _form: '\Drupal\search\Form\SearchSettingsForm' requirements: _permission: 'administer search' + search_reindex_confirm: pattern: '/admin/config/search/settings/reindex' defaults: - _form: 'Drupal\search\Form\ReindexConfirm' + _form: '\Drupal\search\Form\ReindexConfirm' requirements: _permission: 'administer search' search_view: - pattern: 'search/{plugin_id}/{keys}' + pattern: '/search/{plugin_id}/{keys}' defaults: - _content: 'Drupal\search\Controller\SearchController::searchView' + _content: '\Drupal\search\Controller\SearchController::view' plugin_id: NULL keys: '' requirements: