function CKEditor5PluginDefinition::validateConfiguration

Same name in other branches
  1. 10 core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateConfiguration()
  2. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateConfiguration()

Validates the given configuration array.

Parameters

array $configuration: The configuration to validate.

Return value

string|null NULL if there are no validation errors, a string containing the schema violation error messages otherwise.

1 call to CKEditor5PluginDefinition::validateConfiguration()
CKEditor5PluginDefinition::validateDrupalAspects in core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php
Validates the Drupal aspects of the CKEditor 5 plugin definition.

File

core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php, line 262

Class

CKEditor5PluginDefinition
Provides an implementation of a CKEditor 5 plugin definition.

Namespace

Drupal\ckeditor5\Plugin

Code

private function validateConfiguration(array $configuration) : ?string {
    if (!isset($this->schema)) {
        $configuration_name = sprintf("ckeditor5.plugin.%s", $this->id);
        // TRICKY: SchemaCheckTrait::checkConfigSchema() dynamically adds a
        // 'langcode' key-value pair that is irrelevant here. Also,
        // ::checkValue() may (counter to its docs) trigger an exception.
        $this->configName = 'STRIP';
        $this->schema = $this->getTypedConfig()
            ->createFromNameAndData($configuration_name, $configuration);
    }
    $schema_errors = [];
    foreach ($configuration as $key => $value) {
        try {
            $schema_error = $this->checkValue($key, $value);
        } catch (\InvalidArgumentException $e) {
            $schema_error = [
                $key => $e->getMessage(),
            ];
        }
        $schema_errors = array_merge($schema_errors, $schema_error);
    }
    $formatted_schema_errors = [];
    foreach ($schema_errors as $key => $value) {
        $formatted_schema_errors[] = sprintf("[%s] %s", str_replace('STRIP:', '', $key), trim($value, '.'));
    }
    if (!empty($formatted_schema_errors)) {
        return sprintf('The following errors were found: %s.', implode(', ', $formatted_schema_errors));
    }
    return NULL;
}

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