diff --git a/core/modules/search/lib/Drupal/search/Controller/SearchController.php b/core/modules/search/lib/Drupal/search/Controller/SearchController.php index 4e01a3c..6b93a77 100644 --- a/core/modules/search/lib/Drupal/search/Controller/SearchController.php +++ b/core/modules/search/lib/Drupal/search/Controller/SearchController.php @@ -109,7 +109,22 @@ public function view(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(SearchForm::create($this->container()), $plugin); - $build['search_results'] = $results; + + $build['search_results'] = array( + '#theme' => array('item_list__search_results__' . $plugin_id, 'item_list__search_results'), + '#items' => $results, + '#empty' => array( + // @todo Revisit where this help text is added. + '#markup' => '

' . $this->t('Your search yielded no results.') . '

' . search_help('search#noresults', drupal_help_arg()), + ), + '#title' => $this->t('Search Results'), + '#list_type' => 'ol', + ); + + $build['pager'] = array( + '#theme' => 'pager', + ); + return $build; } diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php index 21478fe..ea36358 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php @@ -74,10 +74,10 @@ public function isSearchExecutable(); public function execute(); /** - * Executes the search and builds a render array. + * Executes the search and builds render arrays for the result items. * * @return array - * The search results in a renderable array. + * An array of search_result render arrays. */ public function buildResults(); diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php index 7f534d5..f5c3100 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php @@ -80,11 +80,17 @@ public function isSearchExecutable() { */ public function buildResults() { $results = $this->execute(); - return array( - '#theme' => 'search_results', - '#results' => $results, - '#plugin_id' => $this->getPluginId(), - ); + + $built = array(); + foreach ($results as $result) { + $built[] = array( + '#theme' => 'search_result', + '#result' => $result, + '#plugin_id' => $this->getPluginId(), + ); + } + + return $built; } /** diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 3fc2953..e6ee130 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -111,11 +111,6 @@ function search_theme() { 'file' => 'search.pages.inc', 'template' => 'search-result', ), - 'search_results' => array( - 'variables' => array('results' => NULL, 'plugin_id' => NULL), - 'file' => 'search.pages.inc', - 'template' => 'search-results', - ), ); } diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index 023a825..ec71855 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -6,35 +6,6 @@ */ use Drupal\Core\Language\Language; -use Symfony\Component\HttpFoundation\RedirectResponse; - -/** - * Prepares variables for search results templates. - * - * Default template: search-results.html.twig. - * - * @param array $variables - * An array with the following elements: - * - results: Search results array. - * - plugin_id: Plugin the search results came from. - */ -function template_preprocess_search_results(&$variables) { - $variables['search_results'] = ''; - if (!empty($variables['plugin_id'])) { - $variables['plugin_id'] = check_plain($variables['plugin_id']); - } - foreach ($variables['results'] as $result) { - $variables['search_results'][] = array( - '#theme' => 'search_result', - '#result' => $result, - '#plugin_id' => $variables['plugin_id'], - ); - } - $variables['pager'] = array('#theme' => 'pager'); - // @todo Revisit where this help text is added, see also - // http://drupal.org/node/1918856. - $variables['help'] = search_help('search#noresults', drupal_help_arg()); -} /** * Implements hook_theme_suggestions_HOOK(). diff --git a/core/modules/search/templates/search-result.html.twig b/core/modules/search/templates/search-result.html.twig index 281f8b1..aa1bcfd 100644 --- a/core/modules/search/templates/search-result.html.twig +++ b/core/modules/search/templates/search-result.html.twig @@ -3,9 +3,7 @@ * @file * Default theme implementation for displaying a single search result. * - * This template renders a single search result and is collected into - * search-results.html.twig. This and the parent template are - * dependent to one another sharing the markup for ordered lists. + * This template renders a single search result. * * Available variables: * - url: URL of the result. @@ -57,18 +55,16 @@ * @ingroup themeable */ #} -
  • - {{ title_prefix }} -

    - {{ title }} -

    - {{ title_suffix }} -
    - {% if snippet %} -

    {{ snippet }}

    - {% endif %} - {% if info %} -

    {{ info }}

    - {% endif %} -
    -
  • +{{ title_prefix }} +

    + {{ title }} +

    +{{ title_suffix }} +
    + {% if snippet %} +

    {{ snippet }}

    + {% endif %} + {% if info %} +

    {{ info }}

    + {% endif %} +
    diff --git a/core/modules/search/templates/search-results.html.twig b/core/modules/search/templates/search-results.html.twig deleted file mode 100644 index 4c14be7..0000000 --- a/core/modules/search/templates/search-results.html.twig +++ /dev/null @@ -1,35 +0,0 @@ -{# -/** - * @file - * Default theme implementation for displaying search results. - * - * This template collects each invocation of theme_search_result(). This and - * the child template are dependent to one another sharing the markup for - * definition lists. - * - * Note that modules may implement their own search type and theme function - * completely bypassing this template. - * - * Available variables: - * - search_results: All results as it is rendered through - * search-result.html.twig. - * - plugin_id: The machine-readable name of the plugin being executed, such - * as 'node_search' or 'user_search'. - * - pager: The pager next/prev links to display, if any. - * - help: HTML for help text to display when no results are found. - * - * @see template_preprocess_search_results() - * - * @ingroup themeable - */ -#} -{% if search_results %} -

    {{ 'Search results'|t }}

    -
      - {{ search_results }} -
    - {{ pager }} -{% else %} -

    {{ 'Your search yielded no results'|t }}

    - {{ help }} -{% endif %}