You are here

public function CustomConfig::settingsForm in CKEditor custom config 8.3

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

Returns a settings form to configure this CKEditor plugin.

If the plugin's behavior depends on extensive options and/or external data, then the implementing module can choose to provide a separate, global configuration page rather than per-text-editor settings. In that case, this form should provide a link to the separate settings page.

Parameters

array $form: An empty form array to be populated with a configuration form, if any.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the entire filter administration form.

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

Return value

array A render array for the settings form.

Overrides CKEditorPluginConfigurableInterface::settingsForm

File

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

Class

CustomConfig
Defines the "customconfig" plugin.

Namespace

Drupal\ckeditor_config\Plugin\CKEditorPlugin

Code

public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
  $config = [
    'ckeditor_custom_config' => '',
  ];
  $settings = $editor
    ->getSettings();
  if (isset($settings['plugins']['customconfig'])) {
    $config = $settings['plugins']['customconfig'];
  }

  // Load Editor settings.
  $settings = $editor
    ->getSettings();
  $form['ckeditor_custom_config'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('CKEditor Custom Configuration'),
    '#default_value' => $config['ckeditor_custom_config'],
    '#description' => $this
      ->t('Each line may contain a CKEditor configuration setting formatted as "<code>[setting.name] = [value]</code>" with the value being formatted as valid JSON. See <a href="@url">https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html</a> for more details. Note: the examples in the official documentation are provided in Javascript, not JSON.<br><br>Examples: \'<code>forcePasteAsPlainText = true</code>\', \'<code>forceSimpleAmpersand = false</code>\', \'<code>removePlugins = "font"</code>\', \'<code>tabIndex = 3</code>\', \'<code>format_h2 = { "element": "h2", "attributes": { "class": "contentTitle2" } }</code>\'', [
      '@url' => 'https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html',
    ]),
    '#attached' => [
      'library' => [
        'ckeditor_config/ckeditor_config.customconfig',
      ],
    ],
    '#element_validate' => [
      [
        $this,
        'validateCustomConfig',
      ],
    ],
  ];
  return $form;
}