Commit 5bac28df authored by shkiper's avatar shkiper Committed by borisson_

Issue #2796143 by shkiper, borisson_, johndevman, StryKaizer: Improve theming...

Issue #2796143 by shkiper, borisson_, johndevman, StryKaizer: Improve theming experience by adding a list template for facet
parent c5bde53c
......@@ -37,17 +37,26 @@ function facets_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function facets_theme($existing, $type, $theme, $path) {
$result_item_variables = [
'variables' => [
'value' => '',
'show_count' => FALSE,
'count' => NULL,
'is_active' => FALSE,
],
];
return [
'facets_result_item' => $result_item_variables,
'facets_result_item' => [
'variables' => [
'value' => '',
'show_count' => FALSE,
'count' => NULL,
'is_active' => FALSE,
],
],
'facets_item_list' => [
'variables' => [
'items' => [],
'title' => '',
'list_type' => 'ul',
'wrapper_attributes' => [],
'attributes' => [],
'empty' => NULL,
'context' => [],
],
],
];
}
......@@ -179,3 +188,26 @@ function facets_entity_predelete(EntityInterface $entity) {
$facet_source_plugin_manager->clearCachedDefinitions();
}
}
/**
* Prepares variables for facets item list templates.
*
* Default template: facets-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_preprocess_facets_item_list(&$variables) {
template_preprocess_item_list($variables);
}
......@@ -109,7 +109,7 @@ class DateBasicWidget extends WidgetPluginBase {
}, $facet->getResults());
return [
'#theme' => 'item_list',
'#theme' => 'facets_item_list',
'#items' => $items,
'#attributes' => ['data-drupal-facet-id' => $facet->id()],
'#cache' => [
......
......@@ -61,7 +61,7 @@ abstract class WidgetPluginBase extends PluginBase implements WidgetPluginInterf
$widget = $facet->getWidget();
return [
'#theme' => 'item_list',
'#theme' => 'facets_item_list',
'#items' => $items,
'#attributes' => [
'data-drupal-facet-id' => $facet->id(),
......@@ -151,7 +151,7 @@ abstract class WidgetPluginBase extends PluginBase implements WidgetPluginInterf
}
$items['children'] = [
'#theme' => 'item_list',
'#theme' => 'facets_item_list',
'#items' => $child_items,
];
......
{#
/**
* @file
* Default theme implementation for a facets 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_preprocess_facets_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