You are here

public function Wordcount::settingsForm in CKEditor Wordcount 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/CKEditorPlugin/Wordcount.php \Drupal\ckwordcount\Plugin\CKEditorPlugin\Wordcount::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/Wordcount.php, line 76

Class

Wordcount
Defines the "wordcount" plugin.

Namespace

Drupal\ckwordcount\Plugin\CKEditorPlugin

Code

public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
  $settings = $editor
    ->getSettings();
  $form['enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable the counter'),
    '#default_value' => !empty($settings['plugins']['wordcount']['enable']) ? $settings['plugins']['wordcount']['enable'] : FALSE,
  ];
  $form['show_remaining'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show remaining'),
    '#default_value' => !empty($settings['plugins']['wordcount']['show_remaining']) ? $settings['plugins']['wordcount']['show_remaining'] : FALSE,
  ];
  $form['show_paragraphs'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show the paragraphs count'),
    '#default_value' => !empty($settings['plugins']['wordcount']['show_paragraphs']) ? $settings['plugins']['wordcount']['show_paragraphs'] : FALSE,
  ];
  $form['show_word_count'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show the word count'),
    '#default_value' => !empty($settings['plugins']['wordcount']['show_word_count']) ? $settings['plugins']['wordcount']['show_word_count'] : FALSE,
  ];
  $form['show_char_count'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show the character count'),
    '#default_value' => !empty($settings['plugins']['wordcount']['show_char_count']) ? $settings['plugins']['wordcount']['show_char_count'] : FALSE,
  ];
  $form['count_bytes'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Count bytes'),
    '#default_value' => !empty($settings['plugins']['wordcount']['count_bytes']) ? $settings['plugins']['wordcount']['count_bytes'] : FALSE,
  ];
  $form['count_spaces'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Count spaces as characters'),
    '#default_value' => !empty($settings['plugins']['wordcount']['count_spaces']) ? $settings['plugins']['wordcount']['count_spaces'] : FALSE,
  ];
  $form['count_html'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Count HTML as characters'),
    '#default_value' => !empty($settings['plugins']['wordcount']['count_html']) ? $settings['plugins']['wordcount']['count_html'] : FALSE,
  ];
  $form['count_line_breaks'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Count line breaks'),
    '#default_value' => !empty($settings['plugins']['wordcount']['count_line_breaks']) ? $settings['plugins']['wordcount']['count_line_breaks'] : FALSE,
  ];
  $form['max_words'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Maximum word limit'),
    '#description' => $this
      ->t('Enter a maximum word limit. Leave this set to -1 for unlimited.'),
    '#default_value' => !empty($settings['plugins']['wordcount']['max_words']) ? $settings['plugins']['wordcount']['max_words'] : -1,
  ];
  $form['max_chars'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Maximum character limit'),
    '#description' => $this
      ->t('Enter a maximum character limit. Leave this set to -1 for unlimited.'),
    '#default_value' => !empty($settings['plugins']['wordcount']['max_chars']) ? $settings['plugins']['wordcount']['max_chars'] : -1,
  ];
  $form['hard_limit'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Lock editor when limit is reached'),
    '#default_value' => isset($settings['plugins']['wordcount']['hard_limit']) ? $settings['plugins']['wordcount']['hard_limit'] : TRUE,
  ];
  $form['max_words']['#element_validate'][] = [
    $this,
    'isNumeric',
  ];
  $form['max_chars']['#element_validate'][] = [
    $this,
    'isNumeric',
  ];
  return $form;
}