function ComponentMetadata::parseSchemaInfo

Same name in this branch
  1. 11.x core/modules/sdc/src/Component/ComponentMetadata.php \Drupal\sdc\Component\ComponentMetadata::parseSchemaInfo()
Same name and namespace in other branches
  1. 10 core/modules/sdc/src/Component/ComponentMetadata.php \Drupal\sdc\Component\ComponentMetadata::parseSchemaInfo()

Parse the schema information.

Parameters

array $metadata_info: The metadata information as decoded from the component definition file.

Throws

\Drupal\Core\Render\Component\Exception\InvalidComponentException

1 call to ComponentMetadata::parseSchemaInfo()
ComponentMetadata::__construct in core/lib/Drupal/Core/Theme/Component/ComponentMetadata.php
ComponentMetadata constructor.

File

core/lib/Drupal/Core/Theme/Component/ComponentMetadata.php, line 140

Class

ComponentMetadata
Component metadata.

Namespace

Drupal\Core\Theme\Component

Code

private function parseSchemaInfo(array $metadata_info) : void {
    if (empty($metadata_info['props'])) {
        if ($this->mandatorySchemas) {
            throw new InvalidComponentException(sprintf('The component "%s" does not provide schema information. Schema definitions are mandatory for components declared in modules. For components declared in themes, schema definitions are only mandatory if the "enforce_prop_schemas" key is set to "true" in the theme info file.', $metadata_info['id']));
        }
        $schema = NULL;
    }
    else {
        $schema = $metadata_info['props'];
        if (($schema['type'] ?? 'object') !== 'object') {
            throw new InvalidComponentException('The schema for the props in the component metadata is invalid. The schema should be of type "object".');
        }
        if ($schema['additionalProperties'] ?? FALSE) {
            throw new InvalidComponentException('The schema for the %s in the component metadata is invalid. Arbitrary additional properties are not allowed.');
        }
        $schema['additionalProperties'] = FALSE;
        // 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',
            ]);
        }
    }
    $this->schema = $schema;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.