You are here

private function CKEditor5PluginDefinition::validateConfiguration in Drupal 10

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 260

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;
}