You are here

public function CustomConfig::validateCustomConfig in CKEditor custom config 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/CKEditorPlugin/CustomConfig.php \Drupal\ckeditor_config\Plugin\CKEditorPlugin\CustomConfig::validateCustomConfig()

Custom validator for the "custom_config" element in settingsForm().

File

src/Plugin/CKEditorPlugin/CustomConfig.php, line 120

Class

CustomConfig
Defines the "customconfig" plugin.

Namespace

Drupal\ckeditor_config\Plugin\CKEditorPlugin

Code

public function validateCustomConfig(array $element, FormStateInterface $form_state) {

  // Convert submitted value into an array. Return is empty.
  $config_value = $element['#value'];
  if (empty($config_value)) {
    return;
  }
  $config_array = preg_split('/\\R/', $config_value);

  // Loop through lines.
  $i = 1;
  foreach ($config_array as $value) {

    // Check that syntax matches "[something] = [something]".
    preg_match('/(.*?) \\= (.*)/', $value, $matches);
    if (empty($matches)) {
      $form_state
        ->setError($element, $this
        ->t('The configuration syntax on line @line is incorrect.', [
        '@line' => $i,
      ]));
    }
    $i++;
  }
}