[beta4] Always use default() filter with random function()

Created on 9 August 2023, over 1 year ago
Updated 18 September 2023, about 1 year ago

Problem/Motivation

We are using random() Twig function to generate IDs:

  • sometimes it's the default value of a prop (carousel_id, item_id, id...): {{ carousel_id|default("carousel-" ~ random() ) }} and it's OK, nothing to say
  • sometimes it's used directly carousel-{{ random() }} and it makes unit testing impossible because it generates a different template each time when we have the same input slots & props.

With UI Patterns, we don't do these unit tests yet (from preview data) but we shouldn't make them impossible.

Remaining tasks

TODO for each:

  1. Add a new prop fo the id
  2. Use default() filter
accordion/pattern-accordion.html.twig:    {% set id = 'accordion-' ~ random() %}
breadcrumb/pattern-breadcrumb.html.twig:  {% set id = 'breadcrumb-'~random() %}
header/pattern-header.html.twig:                  {% set search_mid = 'modal-' ~ random() %}
header/pattern-header.html.twig:                  {% set mobile_menu_mid = 'modal-' ~ random() %}
nav_menu/pattern-nav-menu.html.twig:    {% set html_id = 'main-menu-'~random() %}
side_menu/pattern-side-menu.html.twig:  {% set html_id = 'sidemenu-' ~ random() %}
summary/pattern-summary.html.twig:{% set title_id = 'fr-summary-title--' ~ random() %}

Out of scope because part of a menu structure:

nav_menu/pattern-nav-menu.html.twig:            {% set item_id = 'menu-'~loop.index~'-'~random() %}
nav_menu/pattern-nav-menu.html.twig:            {% set item_id = 'mega-menu-'~loop.index~'-'~random() %}
side_menu/pattern-side-menu.html.twig:            {% set item_id = 'fr-sidemenu-item-' ~ loop.index ~ '-' ~ random() %}

API changes

yes, but is safe

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024