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

Breadcrumb

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

function ValidKeysConstraint::getAllowedKeys

Returns the list of valid keys.

Parameters

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

Return value

string[] The keys that will be considered valid.

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ValidKeysConstraint.php, line 89

Class

ValidKeysConstraint
Checks that all the keys of a mapping are valid and required keys present.

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

Code

public function getAllowedKeys(ExecutionContextInterface $context) : array {
    $mapping = $context->getObject();
    assert($mapping instanceof Mapping);
    $resolved_type = $mapping->getDataDefinition()
        ->getDataType();
    $valid_keys = $mapping->getValidKeys();
    // If we were given an explicit array of allowed keys, return that.
    if (is_array($this->allowedKeys)) {
        if (!empty(array_diff($this->allowedKeys, $valid_keys))) {
            throw new InvalidArgumentException(sprintf('The type \'%s\' explicitly specifies the allowed keys (%s), but they are not a subset of the statically defined mapping keys in the schema (%s).', $resolved_type, implode(', ', $this->allowedKeys), implode(', ', $valid_keys)));
        }
        return array_intersect($valid_keys, $this->allowedKeys);
    }
    elseif ($this->allowedKeys === '<infer>') {
        return $mapping->getValidKeys();
    }
    throw new InvalidArgumentException("'{$this->allowedKeys}' is not a valid set of allowed keys.");
}

API Navigation

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