function ConfigValidation::validateMapping

Same name in other branches
  1. 9 core/modules/config/tests/config_test/src/ConfigValidation.php \Drupal\config_test\ConfigValidation::validateMapping()
  2. 8.9.x core/modules/config/tests/config_test/src/ConfigValidation.php \Drupal\config_test\ConfigValidation::validateMapping()
  3. 11.x core/modules/config/tests/config_test/src/ConfigValidation.php \Drupal\config_test\ConfigValidation::validateMapping()

Validates a mapping.

Parameters

array $mapping: The data to validate.

\Symfony\Component\Validator\Context\ExecutionContextInterface $context: The validation execution context.

File

core/modules/config/tests/config_test/src/ConfigValidation.php, line 76

Class

ConfigValidation
Provides a collection of validation callbacks for testing purposes.

Namespace

Drupal\config_test

Code

public static function validateMapping($mapping, ExecutionContextInterface $context) {
    // Ensure we are validating the entire mapping by diffing against all the
    // keys.
    $mapping_schema = \Drupal::service('config.typed')->get('config_test.validation')
        ->getValue();
    if ($diff = array_diff_key($mapping, $mapping_schema)) {
        $context->addViolation('Unexpected keys: ' . implode(', ', array_keys($diff)));
    }
}

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