Commit 580dd44a authored by alexpott's avatar alexpott

Revert "Issue #1926344 by jhodgdon, maggo, mdrummond, Cottser, dimboz |...

Revert "Issue #1926344 by jhodgdon, maggo, mdrummond, Cottser, dimboz | jenlampton: Consolidate search-result.html.twig and search-results.html.twig."

This reverts commit c83ff69e.
parent 9ee43fd7
......@@ -68,7 +68,8 @@ public function view(Request $request, SearchPageInterface $entity, $keys = '')
$plugin = $entity->getPlugin();
$plugin->setSearch($keys, $request->query->all(), $request->attributes->all());
$results = array();
// Default results output is an empty string.
$results = array('#markup' => '');
// Process the search form. Note that if there is
// \Drupal::request()->request data, search_form_submit() will cause a
......@@ -87,32 +88,7 @@ public function view(Request $request, SearchPageInterface $entity, $keys = '')
}
// The form may be altered based on whether the search was run.
$build['search_form'] = $this->entityManager()->getForm($entity, 'search');
if (count($results)) {
$build['search_results_title'] = array(
'#markup' => '<h2>' . $this->t('Search results') . '</h2>',
);
}
$build['search_results'] = array(
'#theme' => array('item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'),
'#items' => $results,
'#empty' => array(
// @todo Revisit where this help text is added.
'#markup' => '<h3>' . $this->t('Your search yielded no results.') . '</h3>' . search_help('search#noresults', drupal_help_arg()),
),
'#list_type' => 'ol',
'#attributes' => array(
'class' => array(
'search-results',
$plugin->getPluginId() . '-results',
),
),
);
$build['pager'] = array(
'#theme' => 'pager',
);
$build['search_results'] = $results;
return $build;
}
......
......@@ -72,12 +72,10 @@ public function isSearchExecutable();
public function execute();
/**
* Executes the search and builds render arrays for the result items.
* Executes the search and builds a render array.
*
* @return array
* An array of render arrays of search result items (generally each item
* has '#theme' set to 'search_result'), or an empty array if there are no
* results.
* The search results in a renderable array.
*/
public function buildResults();
......
......@@ -88,17 +88,11 @@ public function isSearchExecutable() {
*/
public function buildResults() {
$results = $this->execute();
$built = array();
foreach ($results as $result) {
$built[] = array(
'#theme' => 'search_result',
'#result' => $result,
'#plugin_id' => $this->getPluginId(),
);
}
return $built;
return array(
'#theme' => 'search_results',
'#results' => $results,
'#plugin_id' => $this->getPluginId(),
);
}
/**
......
......@@ -108,6 +108,11 @@ 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',
),
);
}
......
......@@ -6,6 +6,35 @@
*/
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().
......
......@@ -3,10 +3,9 @@
* @file
* Default theme implementation for displaying a single search result.
*
* This template renders a single search result. The list of results is
* rendered using '#theme' => 'item_list', with suggestions of:
* - item_list__search_results__(plugin_id)
* - item_list__search_results
* 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.
*
* Available variables:
* - url: URL of the result.
......@@ -58,16 +57,18 @@
* @ingroup themeable
*/
#}
{{ title_prefix }}
<h3 class="title"{{ title_attributes }}>
<a href="{{ url }}">{{ title }}</a>
</h3>
{{ title_suffix }}
<div class="search-snippet-info">
{% if snippet %}
<p class="search-snippet"{{ content_attributes }}>{{ snippet }}</p>
{% endif %}
{% if info %}
<p class="search-info">{{ info }}</p>
{% endif %}
</div>
<li {{ attributes }}>
{{ title_prefix }}
<h3 class="title"{{ title_attributes }}>
<a href="{{ url }}">{{ title }}</a>
</h3>
{{ title_suffix }}
<div class="search-snippet-info">
{% if snippet %}
<p class="search-snippet"{{ content_attributes }}>{{ snippet }}</p>
{% endif %}
{% if info %}
<p class="search-info">{{ info }}</p>
{% endif %}
</div>
</li>
{#
/**
* @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 %}
<h2>{{ 'Search results'|t }}</h2>
<ol class="search-results {{ plugin_id }}-results">
{{ search_results }}
</ol>
{{ pager }}
{% else %}
<h2>{{ 'Your search yielded no results'|t }}</h2>
{{ help }}
{% endif %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment