Avoid attribute() function usage

Created on 21 August 2023, over 1 year ago

Problem/Motivation

If used with an object method, the attribute function allows to have a dynamic value for this object method and arguments:

{{ attribute(object, method, arguments) }}

There is no currently identified use case for this in UI Suite / UI Patterns where we avoid all executable object except https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Template!Attribut...

If used with a mapping key, the attribute function works the same than [] notation:

attribute(aria_live_mapping, role)
aria_live_mapping[role]
aria_live_mapping[(role)]

attribute(aria_live_mapping, "alert") 
aria_live_mapping["alert"] 
aria_live_mapping[("alert")]
aria_live_mapping.alert

attribute(aria_live_mapping, "al" ~ "ert") 
aria_live_mapping["al" ~ "ert"] 
aria_live_mapping[("al" ~ "ert")]

They manage error the same way (gracefully, silently):

attribute(aria_live_mapping, "not_existing") 
aria_live_mapping["not_existing"] 
aria_live_mapping[("not_existing")]
aria_live_mapping.not_existing

It seems it triggers the exact same expression internally: https://github.com/twigphp/Twig/blob/3.x/src/Node/Expression/GetAttrExpr...

So, let's avoid this function.

Proposed resolution

remove attribute() from https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...

📌 Task
Status

Fixed

Version

5.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