Constraint slot names allowed by XB in its component tree

Created on 18 April 2025, 4 days ago

Overview

XB added ComponentSourceWithSlotsInterface back when it introduced the concept of "component source plugins" in πŸ“Œ Add support for Blocks as Components Active .

So XB currently does not constraint it at all β€” meaning in theory weird things like an emoji could be a slot name. This risks things breaking deep down. It's easier to reason about XB's data model if it's constrained.

It is currently unconstrained, but because there's only 3 component source plugins (block, SDC, JS) and JS uses SDC's metadata infrastructure, the reality is that SDC's restrictions apply to XB today. Those restrictions are defined in https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas..., specifically:

 "$defs": {
    "slotDefinition": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
…

Proposed resolution

  1. Determine what valid slot names are. This MUST be equal to or a superset of the slot names allowed by SDC.
  2. Expand the validation that runs when saving a Component config entity:
    $source = $component->getComponentSource();
    if ($source instanceof ComponentSourceWithSlotsInterface) {
      $slot_names = array_keys($source->getSlotDefinitions());
      // Validate compliance with /^[a-zA-Z0-9_-]+$/ β€” or a superset thereof.
    }
  3. Test coverage.

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