You are here

public function Wordcount::getConfig in CKEditor Wordcount 8

Same name and namespace in other branches
  1. 2.x src/Plugin/CKEditorPlugin/Wordcount.php \Drupal\ckwordcount\Plugin\CKEditorPlugin\Wordcount::getConfig()

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

File

src/Plugin/CKEditorPlugin/Wordcount.php, line 53

Class

Wordcount
Defines the "wordcount" plugin.

Namespace

Drupal\ckwordcount\Plugin\CKEditorPlugin

Code

public function getConfig(Editor $editor) {
  $settings = $editor
    ->getSettings();
  return [
    'wordcount' => [
      'showRemaining' => !empty($settings['plugins']['wordcount']['show_remaining']) ? $settings['plugins']['wordcount']['show_remaining'] : FALSE,
      'showParagraphs' => !empty($settings['plugins']['wordcount']['show_paragraphs']) ? $settings['plugins']['wordcount']['show_paragraphs'] : FALSE,
      'showWordCount' => !empty($settings['plugins']['wordcount']['show_word_count']) ? $settings['plugins']['wordcount']['show_word_count'] : FALSE,
      'showCharCount' => !empty($settings['plugins']['wordcount']['show_char_count']) ? $settings['plugins']['wordcount']['show_char_count'] : FALSE,
      'countBytesAsChars' => !empty($settings['plugins']['wordcount']['count_bytes']) ? $settings['plugins']['wordcount']['count_bytes'] : FALSE,
      'countSpacesAsChars' => !empty($settings['plugins']['wordcount']['count_spaces']) ? $settings['plugins']['wordcount']['count_spaces'] : FALSE,
      'countHTML' => !empty($settings['plugins']['wordcount']['count_html']) ? $settings['plugins']['wordcount']['count_html'] : FALSE,
      'countLineBreaks' => !empty($settings['plugins']['wordcount']['count_line_breaks']) ? $settings['plugins']['wordcount']['count_line_breaks'] : FALSE,
      'maxWordCount' => !empty($settings['plugins']['wordcount']['max_words']) ? $settings['plugins']['wordcount']['max_words'] : -1,
      'maxCharCount' => !empty($settings['plugins']['wordcount']['max_chars']) ? $settings['plugins']['wordcount']['max_chars'] : -1,
      'hardLimit' => isset($settings['plugins']['wordcount']['hard_limit']) ? $settings['plugins']['wordcount']['hard_limit'] : TRUE,
    ],
  ];
}