function SchemaCompatibilityChecker::isCompatible

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Theme/Component/SchemaCompatibilityChecker.php \Drupal\Core\Theme\Component\SchemaCompatibilityChecker::isCompatible()
Same name in other branches
  1. 10 core/modules/sdc/src/Component/SchemaCompatibilityChecker.php \Drupal\sdc\Component\SchemaCompatibilityChecker::isCompatible()
  2. 10 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\sdc\Exception\IncompatibleComponentSchema

1 call to SchemaCompatibilityChecker::isCompatible()
SchemaCompatibilityChecker::checkSharedProperties in core/modules/sdc/src/Component/SchemaCompatibilityChecker.php
Checks that the shared properties are compatible.

File

core/modules/sdc/src/Component/SchemaCompatibilityChecker.php, line 37

Class

SchemaCompatibilityChecker
Checks whether two schemas are compatible.

Namespace

Drupal\sdc\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.