Commit c5bde53c authored by shkiper's avatar shkiper Committed by borisson_

Issue #2846343 by shkiper, borisson_: Improve theming experience by adding a...

Issue #2846343 by shkiper, borisson_: Improve theming experience by adding a list template for facet summary
parent 38522fc1
......@@ -44,6 +44,17 @@ function facets_summary_theme($existing, $type, $theme, $path) {
'message' => '',
],
],
'facets_summary_item_list' => [
'variables' => [
'items' => [],
'title' => '',
'list_type' => 'ul',
'wrapper_attributes' => [],
'attributes' => [],
'empty' => NULL,
'context' => [],
],
],
];
}
......@@ -62,3 +73,26 @@ function facets_summary_theme_suggestions_facets_summary_facet_result(array $var
// Add suggestions as: facets-summary-facet-result--{facet_id}.
return [$variables['theme_hook_original'] . '__' . $variables['facet_id']];
}
/**
* Prepares variables for facets summary item list templates.
*
* Default template: facets-summary-item-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - items: An array of items to be displayed in the list. Each item can be
* either a string or a render array. If #type, #theme, or #markup
* properties are not specified for child render arrays, they will be
* inherited from the parent list, allowing callers to specify larger
* nested lists without having to explicitly specify and repeat the
* render properties for all nested child lists.
* - title: A title to be prepended to the list.
* - list_type: The type of list to return (e.g. "ul", "ol").
* - wrapper_attributes: HTML attributes to be applied to the list wrapper.
*
* @see https://www.drupal.org/node/1842756
*/
function facets_summary_preprocess_facets_summary_item_list(&$variables) {
template_preprocess_item_list($variables);
}
......@@ -109,7 +109,7 @@ class DefaultFacetsSummaryManager {
}
$build = array(
'#theme' => 'item_list',
'#theme' => 'facets_summary_item_list',
'#attributes' => array(
'data-drupal-facets-summary-id' => $facets_summary->id(),
),
......
{#
/**
* @file
* Default theme implementation for a facets summary item list.
*
* 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").
* - wrapper_attributes: HTML attributes to be applied to the list wrapper.
* - 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: A list of contextual data associated with the list. May contain:
* - list_style: The custom list style.
*
* @see facets_summary_preprocess_facets_summary_item_list()
*
* @ingroup themeable
*/
#}
{% if context.list_style %}
{%- set attributes = attributes.addClass('item-list__' ~ context.list_style) %}
{% endif %}
{% if items or empty %}
{%- if title is not empty -%}
<h3>{{ title }}</h3>
{%- endif -%}
{%- if items -%}
<{{ list_type }}{{ attributes }}>
{%- for item in items -%}
<li{{ item.attributes }}>{{ item.value }}</li>
{%- endfor -%}
</{{ list_type }}>
{%- else -%}
{{- empty -}}
{%- endif -%}
{%- 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