[2.0.0-beta1] Check #attributes processing with pattern() and component() functions

Created on 20 July 2024, about 2 months ago
Updated 12 August 2024, 27 days ago

Problem/Motivation

pattern Twig function from ui_patterns_legacy has this signature: (string $id, array $fields = [], $variant = "")

So, attributes object must be passed with $fields, mixed with the other props and the slots.

component Twig function has this signature: (string $component_id, array $slots = [], array $props = [])

So, attributes object must be passed with $props, mixed with the other props.

Proposed resolution

Is attributes correctly moved to #attributes property before being processed by SDC render element ?

Some tests with https://www.drupal.org/project/ui_suite_uswds show it may be failing.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Merge Requests

Comments & Activities

  • Issue created by @pdureau
  • 🇫🇷France pdureau Paris

    It is not a UI Patterns 2 issue but a Core SDC issue.

    #attributes property, which is an expected "classic" of render elements is not processed:

    [
        "#type" => "component",
        "#component" => "ui_suite_uswds:logo",
        "#attributes" => [
          "foo" => "bar",
        ],
        "#slots" => [
          "content" => "Heloooo",
        ]
    ]
    

    That's not good because many Drupal mechanisms are expecting this render property and inject data in it.

    That also shows than, one year after the landing of SDC in Drupal Core, only a few people is using it with the Render API.

    A dirty fix would be to add this to ComponentElement::preRenderComponent():

        if (isset($element["#attributes"])) {
          $props["attributes"] = new Attribute($element["#attributes"]);
        }
    

    But we need to :

    • consider the merging with existing values in $props["attributes"]
    • check where the default attribute object is created (not in ComponentElement, which is surprising)
    • pdureau committed 5b7e80b6 on 2.0.x
      Issue #3462818 by pdureau: Support #attributes render property
      
  • Issue was unassigned.
  • Status changed to Fixed about 1 month ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024