function ComponentValidator::nullifyClassPropsSchema

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Theme/Component/ComponentValidator.php \Drupal\Core\Theme\Component\ComponentValidator::nullifyClassPropsSchema()
Same name in other branches
  1. 10 core/modules/sdc/src/Component/ComponentValidator.php \Drupal\sdc\Component\ComponentValidator::nullifyClassPropsSchema()
  2. 10 core/lib/Drupal/Core/Theme/Component/ComponentValidator.php \Drupal\Core\Theme\Component\ComponentValidator::nullifyClassPropsSchema()

Utility method to ensure the schema for class props is set to 'null'.

Parameters

array $schema_props: The schema for all the props.

array $classes_per_prop: Associative array that associates prop names with their prop classes.

Return value

array The new schema.

2 calls to ComponentValidator::nullifyClassPropsSchema()
ComponentValidator::validateClassProps in core/modules/sdc/src/Component/ComponentValidator.php
Validates the props that are not JSON Schema.
ComponentValidator::validateDefinition in core/modules/sdc/src/Component/ComponentValidator.php
Validates the component metadata file.

File

core/modules/sdc/src/Component/ComponentValidator.php, line 300

Class

ComponentValidator
Validates a component based on its definition and the component schema.

Namespace

Drupal\sdc\Component

Code

private function nullifyClassPropsSchema(array $schema_props, array $classes_per_prop) : array {
    foreach ($schema_props['properties'] as $prop_name => $prop_def) {
        $class_types = $classes_per_prop[$prop_name] ?? [];
        // Remove the non JSON Schema types for later JSON Schema validation.
        $types = (array) ($prop_def['type'] ?? [
            'null',
        ]);
        $types = array_diff($types, $class_types);
        $types = empty($types) ? [
            'null',
        ] : $types;
        $schema_props['properties'][$prop_name]['type'] = $types;
    }
    return $schema_props;
}

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