bootstrap_italia-8.x-0.x-dev/components/components-2/list/linklist-item.html.twig
components/components-2/list/linklist-item.html.twig
{#
/**
* @file
* Template for linklist-item component.
* Docs: https://italia.github.io/bootstrap-italia/docs/organizzare-i-contenuti/liste/#liste-per-men%C3%B9-di-navigazione
* Latest revision: v2.11.2
*
* Parameters:
* - item, item contains:
* - attributes: HTML attributes for the menu item.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
* - is_expanded: TRUE if the link has visible children within the current
* menu tree.
* - is_collapsed: TRUE if the link has children within the current menu tree
* that are not currently visible.
* - in_active_trail: TRUE if the link is in the active trail.
* - title_tag (string) (default: 'h3')
* - list_type (string) (default: '')
* - wrapper_tag (string) (default: '')
* - title_wrapper_tag (string) (default: '')
* - level (string) (default: '')
* - verbose_classes (boolean) (default: false)
* - active_items_large (boolean) (default: false)
* - active_items_bold (boolean) (default: false)
* - show_link_description (boolean) (default: false)
* - active_assistive_text (string) (default: '')
* - show_icon (boolean) (default: false)
* - linklist_item_classes (array) (default: '')
* - linklist_item_attributes (obj attribute) (default: '')
*
* Examples:
{% include '@bi-bcl/list/linklist-item.html.twig' with {
item: item,
level: 'x',
list_type: 'dropdown',
} %}
*
*/
#}
{% apply spaceless %}
{# Set defaults #}
{# Check item type: link-item|menu-item #}
{% set _item = item.link['#type'] == 'link' ? item.link : item %}
{% set _title_tag = title_tag|default('h3') %}
{% set _list_type = list_type|default('') %}
{% set _wrapper_tag = wrapper_tag|default('') %}
{% set _title_wrapper_tag = title_wrapper_tag|default('') %}
{% set _level = level|default('') %}
{% set _verbose_classes = verbose_classes ?? false %}
{% set _active_items_large = active_items_large ?? false %}
{% set _active_items_bold = active_items_bold ?? false %}
{% set _show_link_description = show_link_description ?? false %}
{% set _active_assistive_text = active_assistive_text|default('Current page'|trans) %}
{% set _show_icon = show_icon ?? false %}
{% set _linklist_item_classes = linklist_item_classes|default('') %}
{% set _linklist_item_attributes = linklist_item_attributes|default('') %}
{# Set options #}
{% set _classes = [
'list-item',
_list_type is not empty ? _list_type ~ '-item',
_verbose_classes and _level is not empty ? 'nav-link__level-' ~ _level,
_item.in_active_trail ? 'active',
_item.in_active_trail and _active_items_large ? 'large',
_item.in_active_trail and _active_items_bold ? 'medium',
] %}
{% if _linklist_item_classes is not empty %}
{% set _classes = _classes|merge(linklist_item_classes) %}
{% endif %}
{# If is a link item #}
{% if _item['#options'].attributes|length > 0 %}
{% set linklist_item_attributes = _item['#options'].attributes %}
{% set linklist_wrapper_classes = _item['#options'].attributes|join(' ')|trim %}
{# If is a menu item #}
{% elseif _item.attributes|length > 0 %}
{% set linklist_item_attributes = _item.attributes %}
{% set linklist_wrapper_classes = _item.attributes.class|join(' ')|trim %}
{% elseif _linklist_item_attributes is empty %}
{% set linklist_item_attributes = create_attribute() %}
{% set linklist_wrapper_classes = '' %}
{% endif %}
{% set linklist_item_attributes = item.link['#type'] == 'link' ?
linklist_item_attributes|merge({"class": _classes}) :
linklist_item_attributes.addClass(_classes)
%}
{# Link item or menu item #}
{% if _item['#url'].external or _item.url.external %}
{% set linklist_item_attributes = linklist_item_attributes
.setAttribute('target', '_blank')
.setAttribute('rel', 'nofollow')
.setAttribute('aria-label', _item.title ~ ' - ' ~ 'External link'|t ~ ' - ' ~ 'New window'|t)
%}
{% endif %}
{# Component #}
{%- if _wrapper_tag is not empty -%}
<{{ _wrapper_tag }} class="{{ linklist_wrapper_classes }}">
{%- endif -%}
{# If a divider item #}
{%- if _item.title == '<divider>' or _item['#title'] == '<divider>' -%}
<span class="divider"></span>
{# If a Nolink item #}
{%- elseif
(_item.url.isRouted and _item.url.routeName == '<nolink>') or
(_item['#url'].isRouted and _item['#url'].routeName == '<nolink>')
-%}
<{{ _title_tag }} class="link-list-heading">{{ _item.title }}</{{ _title_tag }}>
{# If a button item #}
{%- elseif
(_item.url.isRouted and _item.url.routeName == '<button>') or
(_item['#url'].isRouted and _item['#url'].routeName == '<button>')
-%}
<{{ _title_tag }} class="link-list-heading">{{ _item.title }}</{{ _title_tag }}>
{%- else -%}
{%- set _linklist_title -%}
{% if _show_icon %}
{% include '@bi-bcl/icon/icon.html.twig' with {
name: 'it-arrow-right-triangle',
size: 'sm',
icon_classes: ['me-2']
} %}
{% endif %}
{%- if _title_wrapper_tag is not empty -%}
<{{ _title_wrapper_tag }}{{ item.text_attributes ? item.text_attributes }}>
{%- endif -%}
{%- if _item.title -%}{# Menu item. #}
{{- _item.title -}}
{%- elseif _item['#title'] -%}{# Link item. #}
{{- _item['#title'] -}}
{%- elseif item.text -%}{# Link item no url #}
{{- item.text -}}
{%- elseif _item['#options'].attributes['title'] -%}{# Link item no title #}
{{- _item['#options'].attributes['title'] -}}
{%- endif -%}
{# Original_link only in menu item #}
{%- if _item.original_link.getDescription() and _show_link_description -%}
<small class="d-block">{{ _item.original_link.getDescription() }}</small>
{%- endif -%}
{%- if _title_wrapper_tag is not empty -%}
</{{ _title_wrapper_tag }}>
{%- endif -%}
{# in_active_trail only in menu item #}
{%- if _item.in_active_trail -%}
<span class="visually-hidden">{{ _active_assistive_text }}</span>
{%- endif -%}
{%- endset -%}
{# Menu item. #}
{%- if _item.url -%}
{{ link(_linklist_title, _item.url, linklist_item_attributes) }}
{# Link item. #}
{%- elseif _item['#url'] -%}
{{ link(_linklist_title, _item['#url'], linklist_item_attributes) }}
{# Other. #}
{%- else -%}
{{ _linklist_title }}
{%- endif -%}
{%- endif -%}
{%- if _wrapper_tag is not empty -%}
</{{ _wrapper_tag }}>
{%- endif -%}
{% endapply %}
