Skip to content

Commit

Permalink
Refined menu rel attribute generation, fixed #2573 double value probl…
Browse files Browse the repository at this point in the history
…em (#2585)

* refined menu rel generation, fixed #2573 double problem

* simplified menu rel generation, fixed attr value duplication
  • Loading branch information
thexmanxyz authored and mahagr committed Dec 20, 2019
1 parent b952668 commit 51da034
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions engines/common/nucleus/particles/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,41 @@
{% set dropdown = item.level == 1 ? ' g-' ~ item.getDropdown() %}
{% set parent = item.children ? ' g-parent' %}
{% set target = (item.target != '_self' or context.particle.forceTarget) ? ' target="' ~ item.target|e ~ '"' %}
{% set rel = item.rel %}

{% if item.target == '_blank' %}
{% set relTarget = ('noopener' not in item.rel) ? 'noopener' : '' %}
{% if 'noreferrer' not in item.rel %}
{% set relTarget = (relTarget) ? relTarget ~ ' ' : relTarget %}
{% set relTarget = relTarget ~ 'noreferrer' %}
{% if 'noopener' not in rel %}
{% set rel = rel ? rel ~ ' ' : rel %}
{% set rel = rel ~ 'noopener' %}
{% endif %}
{% if 'noreferrer' not in rel %}
{% set rel = rel ? rel ~ ' ' : rel %}
{% set rel = rel ~ 'noreferrer' %}
{% endif %}
{% set relTarget = (item.rel and relTarget) ? ' ' ~ relTarget : relTarget %}
{% endif %}

{% set listAttributes = '' %}
{% if item.attributes %}
{% for attribute in item.attributes %}
{% for key, value in attribute %}
{% set listAttributes = listAttributes ~ ' ' ~ key|e ~ '="' ~ value|e('html_attr') ~ '"' %}
{% endfor %}
{% endfor %}
{% endif %}

{% set listAttributes = item.attributes|attribute_array %}
{% set linkAttributes = '' %}
{% set relAttribute = '' %}

{% if item.link_attributes %}
{% for attribute in item.link_attributes %}
{% for key, value in attribute %}
{% if key == 'rel' %}
{% set hValue = value|e('html_attr') %}
{% if hValue not in item.rel and hValue not in relTarget %}
{% set relAttribute = (item.rel or relTarget) ? ' ' : '' %}
{% set relAttribute = relAttribute ~ hValue %}
{% endif %}
{% for hVal in value|split(' ') %}
{% if hVal not in rel %}
{% set rel = rel ? rel ~ ' ' : rel %}
{% set rel = rel ~ hVal %}
{% endif %}
{% endfor %}
{% else %}
{% set linkAttributes = linkAttributes ~ ' ' ~ key|e ~ '="' ~ value|e('html_attr') ~ '"' %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
{% set rel = (item.rel or relTarget or relAttribute) ? ' rel="' ~ item.rel|e ~ relTarget ~ relAttribute ~ '"' %}

{% set rel = rel ? ' rel="' ~ rel|e('html_attr') ~ '"' %}

<li class="g-menu-item g-menu-item-type-{{ item.type }} g-menu-item-{{ item.id }}{% if not item.dropdown_hide %}{{ parent }}{% endif %}{{ active }}{{ dropdown }} {% if item.url and item.children %}{% if not item.dropdown_hide %}g-menu-item-link-parent{% endif %}{% endif %} {{ item.class|default('') }}"
{{- self.getCustomWidth(item, menu, 'item', dropdown) }}
{%- if context.particle.renderTitles|default(0) %} title="{{ item.title }}"{% endif %}{{listAttributes|raw}}>
Expand Down

0 comments on commit 51da034

Please sign in to comment.