From 51da0341af92f7bddae1425d2a6be78dc55a5fab Mon Sep 17 00:00:00 2001 From: Andreas Kar Date: Fri, 20 Dec 2019 08:37:39 +0100 Subject: [PATCH] Refined menu rel attribute generation, fixed #2573 double value problem (#2585) * refined menu rel generation, fixed #2573 double problem * simplified menu rel generation, fixed attr value duplication --- .../common/nucleus/particles/menu.html.twig | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/engines/common/nucleus/particles/menu.html.twig b/engines/common/nucleus/particles/menu.html.twig index 62cb3b5f0..2b02ab56b 100644 --- a/engines/common/nucleus/particles/menu.html.twig +++ b/engines/common/nucleus/particles/menu.html.twig @@ -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') ~ '"' %} +