mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/structural_pages.git
synced 2026-05-05 16:35:29 -03:00
Refatora CSS e templates do menu estrutural
Reescreve structural-pages-menu.css com layout horizontal como padrão (análogo ao microsite-nav) e flyout lateral apenas em contexto sidebar. Extrai renderização de itens para structural-pages-menu-item.html.twig e adiciona link "Home" apontando para a URL do ancestral. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
templates/structural-pages-menu-item.html.twig
Normal file
39
templates/structural-pages-menu-item.html.twig
Normal file
@@ -0,0 +1,39 @@
|
||||
{#
|
||||
/**
|
||||
* @file
|
||||
* Template for a single structural pages menu item (recursive).
|
||||
*
|
||||
* Available variables:
|
||||
* - item: Menu item array with keys:
|
||||
* - id: Node ID.
|
||||
* - title: Node title.
|
||||
* - url: Node URL string.
|
||||
* - is_redirect: Whether the link is a redirect.
|
||||
* - children: Array of child items.
|
||||
* - active_trail: Array of node IDs in the active trail.
|
||||
* - depth: Current depth level (integer).
|
||||
*/
|
||||
#}
|
||||
{% set is_active = item.id in active_trail %}
|
||||
{% set has_children = item.children is not empty %}
|
||||
{% set classes = [
|
||||
'menu-item',
|
||||
'structural-pages-menu__item',
|
||||
'structural-pages-menu__item--level-' ~ depth,
|
||||
is_active ? 'menu-item--active-trail structural-pages-menu__item--active-trail' : '',
|
||||
has_children ? 'menu-item--expanded structural-pages-menu__item--has-children' : '',
|
||||
]|filter(c => c is not empty)|join(' ') %}
|
||||
|
||||
<li class="{{ classes }}">
|
||||
<a href="{{ item.url }}"{% if item.is_redirect %} target="_blank"{% endif %} class="structural-pages-menu__link{% if is_active %} is-active structural-pages-menu__link--active-trail{% endif %}">
|
||||
{{- item.title -}}
|
||||
</a>
|
||||
|
||||
{% if has_children %}
|
||||
<ul class="menu sub-menu structural-pages-menu__list structural-pages-menu__list--level-{{ depth + 1 }}">
|
||||
{% for child in item.children %}
|
||||
{% include '@structural_pages/structural-pages-menu-item.html.twig' with {'item': child, 'active_trail': active_trail, 'depth': depth + 1} only %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</li>
|
||||
@@ -5,64 +5,31 @@
|
||||
*
|
||||
* Available variables:
|
||||
* - ancestor: The ancestor entity (term, user, or group).
|
||||
* - ancestor_url: The ancestor URL string.
|
||||
* - tree: Array of menu tree items, each containing:
|
||||
* - id: Node ID.
|
||||
* - title: Node title.
|
||||
* - url: Node URL.
|
||||
* - is_redirect: Whether the link is a redirect.
|
||||
* - depth: Current depth level.
|
||||
* - children: Array of child items.
|
||||
* - entity: The node entity.
|
||||
* - children: Array of child items (same structure).
|
||||
* - active_trail: Array of node IDs in the active trail.
|
||||
* - show_ancestor_title: Whether to show the ancestor title as header.
|
||||
*/
|
||||
#}
|
||||
{{ attach_library('structural_pages/menu') }}
|
||||
{% if tree is not empty %}
|
||||
<nav class="block-menu navigation structural-pages-menu" aria-label="{{ 'Site structure navigation'|t }}">
|
||||
{% if show_ancestor_title and ancestor %}
|
||||
<h2 class="structural-pages-menu__title block-title">
|
||||
<span>
|
||||
{% if ancestor_url %}
|
||||
<a href="{{ ancestor_url }}">{{ ancestor.label }}</a>
|
||||
{% else %}
|
||||
{{ ancestor.label }}
|
||||
{% endif %}
|
||||
</span>
|
||||
</h2>
|
||||
{% endif %}
|
||||
|
||||
<div class="block-content">
|
||||
<ul class="gva_menu structural-pages-menu__list structural-pages-menu__list--level-1">
|
||||
{% if ancestor_url %}
|
||||
<li class="menu-item structural-pages-menu__item structural-pages-menu__item--level-1">
|
||||
<a href="{{ ancestor_url }}" class="structural-pages-menu__link">{{ 'Home'|t }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for item in tree %}
|
||||
{{ _self.menu_item(item, active_trail, 1) }}
|
||||
{% include '@structural_pages/structural-pages-menu-item.html.twig' with {'item': item, 'active_trail': active_trail, 'depth': 1} only %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
{% macro menu_item(item, active_trail, depth) %}
|
||||
{% set is_active = item.id in active_trail %}
|
||||
{% set has_children = item.children is not empty %}
|
||||
{% set classes = [
|
||||
'menu-item',
|
||||
'structural-pages-menu__item',
|
||||
'structural-pages-menu__item--level-' ~ depth,
|
||||
is_active ? 'menu-item--active-trail structural-pages-menu__item--active-trail',
|
||||
has_children ? 'menu-item--expanded structural-pages-menu__item--has-children',
|
||||
] %}
|
||||
|
||||
<li{{ create_attribute().addClass(classes) }}>
|
||||
<a href="{{ item.url }}"{% if item.is_redirect %} target="_blank"{% endif %} class="structural-pages-menu__link{% if is_active %} is-active structural-pages-menu__link--active-trail{% endif %}">
|
||||
{{- item.title -}}
|
||||
</a>
|
||||
|
||||
{% if has_children %}
|
||||
<ul class="menu sub-menu structural-pages-menu__list structural-pages-menu__list--level-{{ depth + 1 }}">
|
||||
{% for child in item.children %}
|
||||
{{ _self.menu_item(child, active_trail, depth + 1) }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endmacro %}
|
||||
|
||||
Reference in New Issue
Block a user