function SchemaCompatibilityChecker::checkRequired

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

Checks that the required properties are compatible.

Parameters

array $original_schema: The original schema.

array $new_schema: The schema of the replacement component.

Return value

array The detected error messages, if any.

1 call to SchemaCompatibilityChecker::checkRequired()
SchemaCompatibilityChecker::isCompatible in core/lib/Drupal/Core/Theme/Component/SchemaCompatibilityChecker.php
Checks if the replacement schema is compatible with the old one.

File

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

Class

SchemaCompatibilityChecker
Checks whether two schemas are compatible.

Namespace

Drupal\Core\Theme\Component

Code

private function checkRequired(array $original_schema, array $new_schema) : array {
    $error_messages = [];
    $original_required = $original_schema['required'] ?? [];
    $new_required = $new_schema['required'] ?? [];
    $missing_required = array_diff($original_required, $new_required);
    if (!empty($missing_required)) {
        $error_messages[] = sprintf('Some of the required properties are missing in the new schema: [%s].', implode(', ', $missing_required));
    }
    $additional_required = array_diff($new_required, $original_required);
    if (!empty($additional_required)) {
        $error_messages[] = sprintf('Some of the new required properties are not allowed by the original schema: [%s].', implode(', ', $additional_required));
    }
    return $error_messages;
}

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