Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SchemaCompatibilityChecker.php

function 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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal