You are here

public function CKEditorPluginManager::injectPluginSettingsForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/src/CKEditorPluginManager.php \Drupal\ckeditor\CKEditorPluginManager::injectPluginSettingsForm()

Injects the CKEditor plugins settings forms as a vertical tabs subform.

Parameters

array &$form: A reference to an associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

File

core/modules/ckeditor/src/CKEditorPluginManager.php, line 165

Class

CKEditorPluginManager
Provides a CKEditor Plugin plugin manager.

Namespace

Drupal\ckeditor

Code

public function injectPluginSettingsForm(array &$form, FormStateInterface $form_state, Editor $editor) {
  $definitions = $this
    ->getDefinitions();
  foreach (array_keys($definitions) as $plugin_id) {
    $plugin = $this
      ->createInstance($plugin_id);
    if ($plugin instanceof CKEditorPluginConfigurableInterface) {
      $plugin_settings_form = [];
      $form['plugins'][$plugin_id] = [
        '#type' => 'details',
        '#title' => $definitions[$plugin_id]['label'],
        '#open' => TRUE,
        '#group' => 'editor][settings][plugin_settings',
        '#attributes' => [
          'data-ckeditor-plugin-id' => $plugin_id,
        ],
      ];

      // Provide enough metadata for the drupal.ckeditor.admin library to
      // allow it to automatically show/hide the vertical tab containing the
      // settings for this plugin. Only do this if it's a CKEditor plugin that
      // just provides buttons, don't do this if it's a contextually enabled
      // CKEditor plugin. After all, in the latter case, we can't know when
      // its settings should be shown!
      if ($plugin instanceof CKEditorPluginButtonsInterface && !$plugin instanceof CKEditorPluginContextualInterface) {
        $form['plugins'][$plugin_id]['#attributes']['data-ckeditor-buttons'] = implode(' ', array_keys($plugin
          ->getButtons()));
      }
      $form['plugins'][$plugin_id] += $plugin
        ->settingsForm($plugin_settings_form, $form_state, $editor);
    }
  }
}