Compatibility of SDC use with display/experience builders

Created on 30 April 2024, 9 months ago

Problem/Motivation

SDC ecosystem is currently lacking a fully working way of using components while building displays (with block, layouts, field formatters...) from admin pages. They are some work currently in progress:

But we are not there yet and it may be hard for the SDC enthusiasts and early adopters to project themselves into a future where we use SDC components mainly from render arrays instead of from Twig templates.

So, today, most of the use of SDC components (in custom, contrib and core projects) seems to rely on "template to template" calls:

{{ include('sdc_examples:my-button', { text: 'Click Me', iconType: 'external' }, with_context = false) }}

{% embed 'sdc_examples:my-card' with { header: label } %} 
  {% block card_body %}
    …
  {% endblock %} 
{% endembed %}

Those calls may cause incompatibly with those site building tools and may be considered as future technical debt.

For example, πŸ“Œ Convert Olivero's teaser into a single directory component Postponed has recently replaced the markup of node--teaser.html.twig by a call to a component:

{% embed "olivero:teaser" with {
  attributes: attributes.addClass(classes),
  author_attributes,
  author_name,
  content,
  ...
  } only %}
 

content variable is where the display build from admin pages (by Manage Display, Layout Builder, Display Suite...) is injected.

So, because the call to this component is now hardcoded, an unwanted olivero:teaser component will wrap the expected display, and the builder will have two solutions:

  • override the node--teaser.html.twig template in a theme to remove the call to this component and directly print content
  • find a way to skip the #theme => node wrapper, at the risk of missing or breaking some features built around this wrapper

Because of this πŸ“Œ Migrate Olivero's comments to use single directory components Needs work , and other similar issues...It would be a pity if Olivero, the default Drupal theme, is becoming incompatible with the strategy of targeting the ambitious site builders by improving the display building experience.

Proposed resolution

In the upcoming SDC + experience builder era, we need to:

  • consider those legacy Drupal templates (node.html.twig, user.html.twig, field.html.twig, block.html.twig, views.html.twig...) as:
  • and/or provide a safe way for the site builders and/or the developers of those display builder tools to print directly the display without loading those templates (so skipping #theme => node , #theme => field , #theme => block ...)
🌱 Plan
Status

Active

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡«πŸ‡·France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • πŸ‡«πŸ‡·France nod_ Lille

    that's at least major given the impact

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Component blocks (Albeit with ui patterns 1) probably has some code that can be referenced here -

    • 1 block per component per entity-type (for context reasons)
    • entity field support with formatters (via above context)
    • token support
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France nod_ Lille

    I agree with the diagnosis and the end goal, and I think shoving components in template is a necessary step.

    We do not have a way to site build the components in core yet. We shouldn't wait to have it to make the components so having template call components is a way to let the community start the components and use it in core. When we have the capability to site build all this yes we need to make use of that capability and stop hardcoding the components in template.

  • e0ipso Can Picafort

    Probably only tangentially related, and off topic. But my mid-term goal would be to replace render arrays (and maybe Form API) with components as well.

    Without having dug too much into this yet, my question is: is this specific of SDC adoption? Or is it also a problem where templates for entities (et al) are not thin wrappers for the render array?

    In other words, would it have been a problem as well with the older version of the template you linked in the IS as an example?

    (added Component Blocks to the IS)

  • πŸ‡¬πŸ‡§United Kingdom catch

    I would love to see more activity on ✨ [META] Expose Title and other base fields in Manage Display Active - that is the primary blocker to configurable entity rendering and it's been open for ten years. We shouldn't be hard-coding field rendering in any core entity templates.

  • e0ipso Can Picafort

    Tagging for summary (and title) update based on #6 and #7.

  • πŸ‡«πŸ‡·France pdureau Paris

    @nod_:

    I agree with the diagnosis and the end goal, and I think shoving components in template is a necessary step.

    So, we may need to introduce a way of safe way for the site builders and/or the developers of those display builder tools to print directly the display without loading those wrapper templates.

    Maybe, a checkbox in Manage Display page to skip #theme => node and others... There are so many mechanism relying on this layer, I don't know how to this without breaking things.

    @e0ipso:

    Probably only tangentially related, and off topic. But my mid-term goal would be to replace render arrays (and maybe Form API) with components as well.

    A big subject :) About Render API. I would want yo get rid of render arrays too, but not all of them. I have the feeling SDC can replace all hook themes and all render elements but 4: component, inline_template, html_tag & link.

    Such a flesh out Render API would be a dream, but I would keep the render arrays which are declarative, nestable, alterable, seralizable, and have power features like attachments, cache management...

    I did a talk about this last month at French Drupal Camp (in English): https://docs.google.com/presentation/d/1Y6tJ4OOJTtCO5lVxEessDlpcRjr33i-p... and I would be happy to discuss about this in another thread.

    About Form API. We (UI Patterns people) are trying to integrate UI components (our own format before, SDC format now) with Form API for years now, without success. It would be a dream to get rid of Form Elements and use a superset of SDC to build forms. Di you already have an idea about how to do it? We can discuss about this in a dedicated issue.

    @e0ipso:

    is this specific of SDC adoption? Or is it also a problem where templates for entities (et al) are not thin wrappers for the render array?

    It was already a problem before SDC adoption, but SDC is putting a spotlight on it and may make the situation worse:

    • if the SDC component is only deporting the existing wrapper to its own template, we now have a 2 layers of wrappers without any benefit:
      • the original template (node.html.twig, user.html.twig, field.html.twig, block.html.twig, views.html.twig...) is till here and even a thinner layer than before
      • we introduced a meaningless, barely reusable, and confusing SDC component
    • if the SDC component is adding markup and logic to the template, we are making this issue more difficult to deal with once we will be able to site build the components in core.

    I don't see any situation where SDC is winning here.

    We have many templates which will shine as SDC components because they are reusable well-defined UI objects: status-messages.html.twig, breadcrumb.html.twig, table.html.twig, image.html.twig, username.html.twig, pager.html.twig, menu.html.twig... Let's focus on them.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Great slides @pdureau - is there a recording anywhere?

  • πŸ‡«πŸ‡·France pdureau Paris

    Thanks for your feedback @larowlan

    There is a recording, but audio only, and in French, so not very useful: https://m.youtube.com/watch?v=APabn8oYr6w

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I'm learning French so it actually is useful because I need the practise πŸ˜‚ - thanks!

  • πŸ‡¬πŸ‡§United Kingdom catch
  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡¬πŸ‡§United Kingdom catch

    Just found (and re-opened) the original issue which led to this one, and I think the way that SDC was implemented is specifically compounding an existing problem and making it a lot harder to fix. When the template/sdc is for something that's not an entity, then it's a bit diifferent, but the more we use template overrides and sdcs for entity rendering itself, we're making things incompatible with manage display/layout builder - essentially breaking parts of core that would otherwise more or less work.

  • πŸ‡·πŸ‡ΈSerbia finnsky

    It was already a problem before SDC adoption, but SDC is putting a spotlight on it and may make the situation worse:

    In other hand we have CSS and javascript better. So in my point of view every decision and especially restrictions should be discussed.

    @catch in the ticket you just reopened
    1. CSS became better.
    2. Still exists ability to reuse this template for comment twig.
    3. a bit more complicated twig but more structured.

  • πŸ‡·πŸ‡ΈSerbia finnsky

    I thought today and would also like to discuss some points in the IS and comments.

    So, because the call to this component is now hardcoded

    Not now. It's worked this way since Olivero's beginning.
    Now there is an SDC layer that greatly simplifies and improves the styles of the teaser and potentially other components (I want to use it for comments).

    But in general, rolling back that Olivero teaser task will not change anything for those modules from the list.

    hardcoded

    I can't call it hardcode.
    This is a completely valid and the ONLY way (for now) (unfortunately) in the core to implement components.
    Those methods that require manipulation in the admin panel and complex config synchronisation may also not be liked by all members of the community.
    I will be very glad when core can offer something different for components.
    But this moment obviously has not yet arrived.

    It would be a pity if Olivero, the default Drupal theme, is becoming incompatible with the strategy of targeting the ambitious site builders by improving the display building experience.

    I personally don't like that Olivero doesn't always strictly follow BEM.
    Contains unnecessary style cascades and so on.
    I also believe that the developers of these ambitious initiatives are very strong and they will be able to rewrite and adapt any template.
    And it will be much easier for them to do this if it will be good component from a front-end point of view. Even if implemented through Twig.

    now have 2 layers of wrappers without gaining any benefit

    Benefit is clean frontend. Smaller flat tree.

    I don't see any situation where SDC is winning here.

    It is not win of SDC but win of frontend component development approach. SDC is tool here.

    But we are not there yet and it may be hard for the SDC enthusiasts and early adopters to project themselves into a future where we use SDC components mainly from render arrays instead of from Twig templates.

    Nobody can predict the future. Not only SDC (actually BEM) enthusiasts.
    And so let's use the only thing we have for now. Until, of course, the best came along.

    So I consider the current issue at least controversial.
    And definitely at this stage we should not prohibit anything or limit the development of components in any way.

  • πŸ‡·πŸ‡ΈSerbia finnsky

    One more thing

    Many templates will shine as SDC components because they are reusable well-defined UI objects: status-messages.html.twig, breadcrumb.html.twig, table.html.twig, image.html.twig, progress-bar.html.twig, pager.html.twig, menu.html.twig... Let's focus on them.

    The listed things are not so much needed as components.
    They are usually written once and do not often need to be changed within the same site.

    Unlike Card, Teaser, Button, Grid and other workhorses of any site. And this is
    node.html.twig, user.html.twig, field.html.twig, block.html.twig, views.html.twig

  • πŸ‡«πŸ‡·France pdureau Paris

    About Form API. We (UI Patterns people) are trying to integrate UI components (our own format until recently, the SDC format now) with Form API for years now, without success. It would be a dream to get rid of Form Elements and use a superset of SDC to build forms. Did you already have an idea about how to do it? We can discuss about this in a dedicated issue.

    See also πŸ“Œ Compatibility between SDC and the Form API Active

Production build 0.71.5 2024