Component instances in exposed `ContentTemplate` slots must use the exposed slot's machine name

Created on 4 June 2025, 3 days ago

Overview

✨ Content templates, part 3b: store exposed slot subtrees on individual entities Active introduced support for populating ContentTemplate-provided exposed slots.

It added test coverage in \Drupal\Tests\experience_builder\Kernel\NodeTemplatesTest::testExposedSlotsAreFilledByEntity()

It opted for this implementation choice:

That means we can merge two sub-trees if we allow content entities to have values in parent_uuid and slot that reference the corresponding parent_uuid/slot combinations in a content template.

However, what we forgot during reviews, is that this approach prevents something identified in πŸ“Œ [PoC] Introduce a `ContentTypeTemplate` config entity Active : to allow an exposed slot to be moved.

i.e. I should be able to delete my foobar exposed slot, and recreate it elsewhere in the ContentTemplate's component tree. That effectively keeps all existing uses of that exposed slot working (visible).

The current approach does not allow for that, because the exposed slot's machine name is not referenced by component instances, but rather the UUID+slot name that that resolves to.

Proposed resolution

  1. Use the exposed slot machine name.
  2. Update the test coverage like so:
    $ git diff tests
    diff --git a/tests/src/Kernel/NodeTemplatesTest.php b/tests/src/Kernel/NodeTemplatesTest.php
    index 00dfeaadc..ba2fd495c 100644
    --- a/tests/src/Kernel/NodeTemplatesTest.php
    +++ b/tests/src/Kernel/NodeTemplatesTest.php
    @@ -221,8 +221,8 @@ HTML;
                   'expression' => 'β„ΉοΈŽstring␟value',
                 ],
               ],
    -          'slot' => 'the_body',
    -          'parent_uuid' => '2842cc6f-9e2b-42a5-8400-e7d6363e08bf',
    +          'slot' => 'custom_content',
    +          'parent_uuid' => NULL, // or: `ContentTemplate` config entity ID, here that would be: `'node.article.full'`
             ],
             // If the entity is targeting a slot that doesn't exist in the template,
             // or is not exposed, it shouldn't be an error.
    

User interface changes

None.

πŸ“Œ Task
Status

Active

Version

0.0

Component

Data model

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

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

Comments & Activities

Production build 0.71.5 2024