parseStylesFormValue example

/** * {@inheritdoc} */
  public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array {
    switch ($cke4_plugin_id) {
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo       case 'stylescombo':
        if (!isset($cke4_plugin_settings['styles'])) {
          $styles = [];
        }
        else {
          [$styles] = Style::parseStylesFormValue($cke4_plugin_settings['styles']);
        }
        return [
          'ckeditor5_style' => [
            'styles' => $styles,
          ],
        ];

      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Language       case 'language':
        // Identical configuration.         return ['ckeditor5_language' => $cke4_plugin_settings];

      
$tag = array_keys($style_element->getAllowedElements())[0];
    $classes = array_keys($style_element->getAllowedElements()[$tag]['class']);
    return [$tag$classes];
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    // Match the config schema structure at ckeditor5.plugin.ckeditor5_style.     $form_value = $form_state->getValue('styles');
    [$styles$unparseable_lines] = self::parseStylesFormValue($form_value);
    if (!empty($unparseable_lines)) {
      $line_numbers = array_keys($unparseable_lines);
      $form_state->setError($form['styles']$this->formatPlural(
        count($unparseable_lines),
        'Line @line-number does not contain a valid value. Enter a valid CSS selector containing one or more classes, followed by a pipe symbol and a label.',
        'Lines @line-numbers do not contain a valid value. Enter a valid CSS selector containing one or more classes, followed by a pipe symbol and a label.',
        [
          '@line-number' => reset($line_numbers),
          '@line-numbers' => implode(', ', $line_numbers),
        ]
      ));
    }
Home | Imprint | This part of the site doesn't use cookies.