function SchemaCompatibilityChecker::isCompatible

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

Checks if the replacement schema is compatible with the old one.

The goal is to ensure existing usages of the original component will not break when the new component takes place.

For the new schema to be compatible with the original it needs to accept all the possible input that the original component allow. Any optional props in the original component, not present in the replacement component should be ignored and not cause validation errors.

Parameters

array $original_schema: The schema to check compatibility against.

array $new_schema: The new schema that should be compatible with.

Throws

\Drupal\Core\Render\Component\Exception\IncompatibleComponentSchema

1 call to SchemaCompatibilityChecker::isCompatible()
SchemaCompatibilityChecker::checkSharedProperties in core/lib/Drupal/Core/Theme/Component/SchemaCompatibilityChecker.php
Checks that the shared properties are compatible.

File

core/lib/Drupal/Core/Theme/Component/SchemaCompatibilityChecker.php, line 35

Class

SchemaCompatibilityChecker
Checks whether two schemas are compatible.

Namespace

Drupal\Core\Theme\Component

Code

public function isCompatible(array $original_schema, array $new_schema) : void {
    $error_messages = [];
    // First check the required properties.
    $error_messages = [
        $error_messages,
        $this->checkRequired($original_schema, $new_schema),
    ];
    // Next, compare the property types to ensure compatibility.
    $error_messages = [
        $error_messages,
        $this->checkSharedProperties($original_schema, $new_schema),
    ];
    // Finally, raise any potential issues that we might have detected.
    if (!empty($error_messages)) {
        $message = implode("\n", $error_messages);
        throw new IncompatibleComponentSchema($message);
    }
}

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