Remove `attributes` prop from all SDCs in the Experience Builder module

Created on 27 August 2024, 22 days ago
Updated 28 August 2024, 22 days ago

Overview

Based on this discussion with Pierre and Wim

Indeed, I would not recommend to add this to your component definitions:

    attributes:
      type: Drupal\Core\Template\Attribute
      name: Attributes
      title: Attributes

Because this prop is injected automatically by SDC anyway.

But most importantly, because using a PHP namespace as a prop type is not JSON Schema compliant. It is an SDC quirk, a Drupalism, we need to get rid off.

Related issue, kind of: āœØ HTML attributes as Twig mappings instead of PHP objects Active

ā€” @pdureau at #3468944-11: Update XB's `image` SDC to comply with best practices, and document those best practices ā†’

We can and should remove the attributes section of components, e.g.

https://git.drupalcode.org/project/experience_builder/-/blob/0.x/compone...

    # @see \Drupal\Core\Template\ComponentsTwigExtension::mergeAdditionalRenderContext()
    attributes:
      type: Drupal\Core\Template\Attribute
      name: Attributes
      title: Attributes

Proposed resolution

Remove them.

User interface changes

šŸ“Œ Task
Status

Postponed: needs info

Component

Code

Created by

šŸ‡ŗšŸ‡øUnited States Kristen Pol Santa Cruz, CA, USA

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

Merge Requests

Comments & Activities

  • Issue created by @Kristen Pol
  • šŸ‡ŗšŸ‡øUnited States Kristen Pol Santa Cruz, CA, USA

    Adding credit.

  • First commit to issue fork.
  • Pipeline finished with Success
    22 days ago
    Total: 278s
    #266700
  • Status changed to Needs review 22 days ago
  • šŸ‡§šŸ‡ŖBelgium Wim Leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    +1 for theory

    First: I'd love to see this simplified: it's very unfortunate that SDC's metadata is all JSON schema, except for this. Both the SDC subsystem and the XB module have to do a fair bit of special casing to make this work. For example, in XB:

    ā€¦
          // TRICKY: `attributes` is a special case ā€” it is kind of a reserved
          // prop.
          // @see \Drupal\sdc\Twig\TwigExtension::mergeAdditionalRenderContext()
          // @see https://www.drupal.org/project/drupal/issues/3352063#comment-15277820
          if ($prop_name === 'attributes') {
            assert($prop_schema['type'][0] === Attribute::class);
            continue;
          }
    ā€¦
    

    ā€¦ but in practice: not sure?

    I'm not quite convinced yet. šŸ˜…

    If this is such a bad practice, then why does every SDC in Drupal core have this?!

    See:

    • core/profiles/demo_umami/themes/umami/components/branding/branding.component.yml
    • core/profiles/demo_umami/themes/umami/components/banner/banner.component.yml (literally the only prop there!)
    • core/themes/olivero/components/teaser/teaser.component.yml (literally the only prop there!)

    So: can you point to a place where this removal was discussed?

  • Status changed to Postponed: needs info 22 days ago
  • šŸ‡§šŸ‡ŖBelgium Wim Leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ
Production build 0.71.5 2024