function IconPackManager::validateDefinition

Validates a definition against the JSON schema specification.

Parameters

array $definition: The definition to alter.

Return value

bool FALSE if the response failed validation, otherwise TRUE.

Throws

\Drupal\Core\Theme\Icon\Exception\IconPackConfigErrorException Thrown when the definition is not valid.

1 call to IconPackManager::validateDefinition()
IconPackManager::processDefinition in core/lib/Drupal/Core/Theme/Icon/Plugin/IconPackManager.php
Performs extra processing on plugin definitions.

File

core/lib/Drupal/Core/Theme/Icon/Plugin/IconPackManager.php, line 403

Class

IconPackManager
Defines an icon pack plugin manager to deal with icons.

Namespace

Drupal\Core\Theme\Icon\Plugin

Code

private function validateDefinition(array $definition) : bool {
    // If the validator isn't set, then the validation library is not installed.
    if (!$this->validator) {
        return TRUE;
    }
    $schema_ref = sprintf('file://%s/%s', $this->appRoot, self::SCHEMA_VALIDATE);
    $schema = (object) [
        '$ref' => $schema_ref,
    ];
    $definition_object = Validator::arrayToObjectRecursive($definition);
    $this->validator
        ->validate($definition_object, $schema, Constraint::CHECK_MODE_COERCE_TYPES);
    if ($this->validator
        ->isValid()) {
        return TRUE;
    }
    $message_parts = array_map(static fn(array $error): string => sprintf("[%s] %s", $error['property'], $error['message']), $this->validator
        ->getErrors());
    $message = implode(", ", $message_parts);
    throw new IconPackConfigErrorException(sprintf('%s:%s Error in definition `%s`:%s', $definition['provider'], $definition['id'], $definition_object->id, $message));
}

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