You are here

public function ScaytCKEditorButton::getConfig in CKEditor SpellCheckAsYouType (SCAYT) 8

Returns the additions to CKEDITOR.config for a specific CKEditor instance.

The editor's settings can be retrieved via $editor->getSettings(), but be aware that it may not yet contain plugin-specific settings, because the user may not yet have configured the form. If there are plugin-specific settings (verify with isset()), they can be found at

$settings = $editor
  ->getSettings();
$plugin_specific_settings = $settings['plugins'][$plugin_id];

Parameters

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

Return value

array A keyed array, whose keys will end up as keys under CKEDITOR.config.

Overrides CKEditorPluginInterface::getConfig

1 call to ScaytCKEditorButton::getConfig()
ScaytCKEditorButton::settingsForm in src/Plugin/CKEditorPlugin/ScaytCKEditorButton.php
Returns a settings form to configure this CKEditor plugin.

File

src/Plugin/CKEditorPlugin/ScaytCKEditorButton.php, line 168

Class

ScaytCKEditorButton
Defines the "scayt" plugin.

Namespace

Drupal\ckeditor_scayt\Plugin\CKEditorPlugin

Code

public function getConfig(Editor $editor) {

  // Defaults that provide expected basic behavior.
  // Doc: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-scayt_disableOptionsStorage.
  $config = [
    'scayt_autoStartup' => TRUE,
    'scayt_sLang' => 'en_GB',
    'scayt_disableOptionsStorage' => [
      'all',
    ],
  ];
  $settings = $editor
    ->getSettings();
  if (isset($settings['plugins']['scayt'])) {
    $config = $settings['plugins']['scayt'] + $config;
    if (isset($config['scayt_disableOptionsStorage']) && is_string($config['scayt_disableOptionsStorage'])) {
      if (empty(trim($config['scayt_disableOptionsStorage']))) {
        unset($config['scayt_disableOptionsStorage']);
      }
      else {
        $config['scayt_disableOptionsStorage'] = explode(',', $config['scayt_disableOptionsStorage']);
        foreach ($config['scayt_disableOptionsStorage'] as $index => $item) {
          $config['scayt_disableOptionsStorage'][$index] = trim($item);
        }
      }
    }

    // Drupal form submission stores integer (0 or 1).
    // It does not work without casting to boolean.
    $config['scayt_autoStartup'] = (bool) $config['scayt_autoStartup'];
  }
  return $config;
}