diff --git a/core/includes/theme.inc b/core/includes/theme.inc index d8f3136..7c766ab 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1774,7 +1774,7 @@ function drupal_common_theme() { 'variables' => array('status' => MARK_NEW), ), 'item_list' => array( - 'variables' => array('items' => array(), 'title' => '', 'list_type' => 'ul', 'attributes' => array(), 'empty' => NULL), + 'variables' => array('items' => array(), 'title' => '', 'list_type' => 'ul', 'attributes' => array(), 'empty' => NULL, 'context' => array()), ), 'feed_icon' => array( 'variables' => array('url' => NULL, 'title' => NULL), diff --git a/core/modules/search/src/Controller/SearchController.php b/core/modules/search/src/Controller/SearchController.php index f51466a..b7b9a8f 100644 --- a/core/modules/search/src/Controller/SearchController.php +++ b/core/modules/search/src/Controller/SearchController.php @@ -117,15 +117,12 @@ public function view(Request $request, SearchPageInterface $entity) { '#markup' => '

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

', ), '#list_type' => 'ol', - '#attributes' => array( - 'class' => array( - 'search-results', - $plugin->getPluginId() . '-results', - ), - ), '#cache' => array( 'tags' => $entity->getCacheTags(), ), + '#context' => array( + 'plugin' => $plugin->getPluginId(), + ), ); // If this plugin uses a search index, then also add the cache tag tracking diff --git a/core/themes/classy/templates/dataset/item-list--search-results.html.twig b/core/themes/classy/templates/dataset/item-list--search-results.html.twig new file mode 100644 index 0000000..e9928fd --- /dev/null +++ b/core/themes/classy/templates/dataset/item-list--search-results.html.twig @@ -0,0 +1,29 @@ +{% extends "item-list.html.twig" %} +{# +/** + * @file + * Theme override for an item list of search results. + * + * Available variables: + * - items: A list of items. Each item contains: + * - attributes: HTML attributes to be applied to each list item. + * - value: The content of the list element. + * - title: The title of the list. + * - list_type: The tag for list element ("ul" or "ol"). + * - attributes: HTML attributes to be applied to the list. + * - empty: A message to display when there are no items. Allowed value is a + * string or render array. + * - context: An list of contextual data associated with the list. For search + * results, the following data is set: + * - plugin: The search plugin ID, for example "node_search". + * + * @see template_preprocess_item_list() + */ +#} +{% + set classes = [ + 'search-results', + context.plugin ~ '-results', + ] +%} +{% set attributes = attributes.addClass(classes) %}