getCKEditor5Config example


  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['enabled_alignments'] = [
      '#type' => 'fieldset',
      '#title' => $this->t('Enabled Alignments'),
      '#description' => $this->t('These are the alignment types that will appear in the alignment dropdown.'),
    ];

    foreach ($this->getPluginDefinition()->getCKEditor5Config()['alignment']['options'] as $alignment_option) {
      $name = $alignment_option['name'];
      $form['enabled_alignments'][$name] = [
        '#type' => 'checkbox',
        '#title' => $this->t($name),
        '#return_value' => $name,
        '#default_value' => in_array($name$this->configuration['enabled_alignments'], TRUE) ? $name : NULL,
      ];
    }

    return $form;
  }

  
/** * {@inheritdoc} */
  public function getCKEditor5PluginConfig(EditorInterface $editor): array {
    $definitions = $this->getEnabledDefinitions($editor);

    // Allow plugin to modify config, such as loading dynamic values.     $config = [];
    foreach ($definitions as $plugin_id => $definition) {
      $plugin = $this->getPlugin($plugin_id$editor);
      $config[$plugin_id] = $plugin->getDynamicPluginConfig($definition->getCKEditor5Config()$editor);
    }

    // CKEditor 5 interprets wildcards from a "CKEditor 5 model element"     // perspective, Drupal interprets wildcards from a "HTML element"     // perspective. GHS is used to reconcile those two perspectives, to ensure     // all expected HTML elements truly are supported.     // The `ckeditor5_wildcardHtmlSupport` is automatically enabled when     // necessary, and only when necessary.     // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()     if (isset($definitions['ckeditor5_wildcardHtmlSupport'])) {
      $allowed_elements = new HTMLRestrictions($this->getProvidedElements(array_keys($definitions)$editor, FALSE));
      

  public static function validChoices(): array {
    $cke5_plugin_manager = \Drupal::service('plugin.manager.ckeditor5.plugin');
    assert($cke5_plugin_manager instanceof CKEditor5PluginManagerInterface);
    $plugin_definition = $cke5_plugin_manager->getDefinition('ckeditor5_heading');
    assert($plugin_definition->getClass() === static::class);
    return array_diff(
      array_column($plugin_definition->getCKEditor5Config()['heading']['options'], 'model'),
      static::ALWAYS_ENABLED_HEADINGS
    );
  }

  /** * Gets all enabled headings. * * @return string[] * The values in the plugins.ckeditor5_heading.enabled_headings configuration * plus the headings that are always enabled. */
  
return $this->ckeditor5['config'];
  }

  /** * Whether this plugin has additional values for the CKEditor 5 configuration. * * @return bool * * @see \Drupal\ckeditor5\Annotation\CKEditor5AspectsOfCKEditor5Plugin::$config */
  public function hasCKEditor5Config(): bool {
    return $this->getCKEditor5Config() !== [];
  }

}
Home | Imprint | This part of the site doesn't use cookies.