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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

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
    
pdureau’s picture

Assigned: pdureau » Unassigned
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.