Allow declaration of template path in SDC

Created on 29 September 2023, about 1 year ago
Updated 24 August 2024, 3 months ago

Problem/Motivation

We are planning to rewrite UI Patterns β†’ upon SDC. To achieve this, we are proposing a few changes and additions:

There is already a template property in component definition, but SDC ComponentPluginManager is always overriding its value :

$template = $this->findAsset(
  $component_directory,
  $definition['machineName'],
   'twig'
);
$definition['template'] = basename($template);

We support the statement of "Single Directory Component" where everything related to the component must fit in the same directory. This is the target, this is the good practice to promote.

However, they are real world examples where components in a Drupal theme are using templates from distinct codebase. The upstream codebase has only Twig templates, shared by various PHP app with Twig, and the Drupal theme is adding the Drupal related stuff, including component definitions.

Proposed resolution

We need to keep this property value if already set in YAML and allows the use of twig namespaces.

name:  Card
template: "@upstream_repo/path/to/template.twig"
props: {}
slots: {}

It may be as simple as adding a condition in ComponentPluginManager.

Remaining tasks

If there is a chance for this feature to be accepted, we (UI Patterns team) can propose a merge request soon.

We have one month before the release of Drupal 10.2.0-alpha1.

API changes

Yes, but not breaking.

✨ Feature request
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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @pdureau
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France andypost

    Curious how this approach compatible with front matter πŸ“Œ Create TemplateDiscovery for plugin managers to use Needs review

  • πŸ‡«πŸ‡·France pdureau Paris
  • e0ipso Can Picafort

    I am not sure about this one. I see where you are coming from, you want to avoid having a dummy component template that only has an include of the upstream component, by moving it to the YML.

    I think having it in the .twig file is better because is not a new thing to learn. A dev new to SDC opens the template and sees a common Twig tag (include, embed, extend, ...) and knows what is going on. If it's in the YML file, they are puzzled by the missing template file that should be there.

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

    I have updated the issue summary to remove references to "distinct template by variant". We understand it can be a messy implementation for an uncommon use case, and we can get rid of this requirement.

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

    I think having it in the .twig file is better because is not a new thing to learn. A dev new to SDC opens the template and sees a common Twig tag (include, embed, extend, ...) and knows what is going on. If it's in the YML file, they are puzzled by the missing template file that should be there.

    Using a dummy component template is a workaround, indeed. But I am proposing to make template property settable in the YAML in order to:

    • avoid a redirection layer
    • be able to list components explicitely using foreign templates (instead of hiding this usage in the Twig code) . Identifying them is important because we agree this is not the best practice to promote. We are targeting single components.

    The template property exists anyway, and it will be explicitly used by alternative discovery πŸ“Œ Make SDC extensible Active , i.e. loading SDC components from non SDC formats (for example,loading SDC components from the legacy UI Patterns 1.x format, or from Patterns Labs).

  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡ΊπŸ‡ΈUnited States Kristen Pol Santa Cruz, CA, USA

    Any new thoughts on this one? And how it relates to:

    ✨ make SDC respect *.info.yml namespaces Active

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

    Hi Kristen,

    Because we (the UI Suite team) got the feeling this issue was controversial, we reorganized the UI Patterns 2.x project to not rely on this any more.

    I still personally thing it would be a good feature, but not something to fight for.

  • πŸ‡ΊπŸ‡ΈUnited States Kristen Pol Santa Cruz, CA, USA

    No problem. I don’t need it but stumbled here when trying to see if I could get rid of using the components module.

Production build 0.71.5 2024