function Heading::buildConfigurationForm

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

Form for choosing which heading tags are available.

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Heading.php, line 94

Class

Heading
CKEditor 5 Heading plugin.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['enabled_headings'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Enabled Headings'),
        '#description' => $this->t('These are the headings that will appear in the headings dropdown. If a heading is not chosen here, it does not necessarily mean the corresponding tag is disallowed in the text format.'),
    ];
    foreach ($this->getPluginDefinition()
        ->getCKEditor5Config()['heading']['options'] as $heading_option) {
        $model = $heading_option['model'];
        if (in_array($model, self::ALWAYS_ENABLED_HEADINGS, TRUE)) {
            continue;
        }
        // It's safe to use $model as a key: listing the same model twice with
        // different properties triggers a schema error in CKEditor 5.
        // @see https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-schema-cannot-register-item-twice
        // @see https://ckeditor.com/docs/ckeditor5/latest/features/headings.html#configuring-custom-heading-elements
        $form['enabled_headings'][$model] = self::generateCheckboxForHeadingOption($heading_option);
        $form['enabled_headings'][$model]['#default_value'] = in_array($model, $this->configuration['enabled_headings'], TRUE) ? $model : NULL;
    }
    return $form;
}

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