[2.0.0-rc2] Move the ComponentMetadata::parseSchemaInfo() workaround to the Schema Manager

Created on 15 January 2025, 7 days ago

Problem/Motivation

In NumberWidget we have this:

    // Because of SDC's ComponentMetadata::parseSchemaInfo() which is adding
    // "object" type to all props to "allows deferring rendering in Twig to the
    // render pipeline". Remove it as soon as this weird mechanism is removed
    // from SDC.
    if (in_array("integer", $this->propDefinition["type"])) {
      $form['value']['#step'] = 1;
    }

A source plugin may be too high level for this workaround

Experience Builder met the same issue and put the workaround deeper in the API:

    $normalized_prop_schema['type'] = SdcPropJsonSchemaType::from(
    // TRICKY: SDC always allowed `object` for Twig integration reasons.
    // @see \Drupal\sdc\Component\ComponentMetadata::parseSchemaInfo()
      is_array($prop_schema['type']) ? $prop_schema['type'][0] : $prop_schema['type']
    )->value;

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

Proposed resolution

Move the workaround to one of the SchemaManager services.

Also:

API changes

No, but let's be very careful.

📌 Task
Status

Active

Version

2.0

Component

Code

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 pdureau Paris

    Not possible to move it to the Schema Manager's Canonicalizer, because Canonicalizer service is called (from ComponentPluginManager::annotateProp() to PropTypePluginManager::getDefinitionFromSchema() to CompatibilityChecker::isCompatible()) before ComponentMetadata::parseSchemaInfo() is executed (ComponentPluginManager::createInstance() to Component::__construct() to ComponentMetadata::__construct()).

    I have tried to alter it by overriding ComponentPluginManager::createInstance() but everything is read-only.

    So, I guess we need to fix this directly in SDC with a Core issue, by simply removing:

          // All props should also support "object" this allows deferring rendering
          // in Twig to the render pipeline.
          $schema_props = $metadata_info['props'];
          foreach ($schema_props['properties'] ?? [] as $name => $prop_schema) {
            $type = $prop_schema['type'] ?? '';
            $schema['properties'][$name]['type'] = array_unique([
              ...(array) $type,
              'object',
            ]);
          }
Production build 0.71.5 2024