You are here

public function CkeditorTemplates::settingsForm in CKEditor Templates 8

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/CkeditorTemplates.php, line 107

Class

CkeditorTemplates
Defines the "Templates" plugin.

Namespace

Drupal\ckeditor_templates\Plugin\CKEditorPlugin

Code

public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {

  // Defaults.
  $config = [
    'replace_content' => FALSE,
    'template_path' => '',
  ];
  $settings = $editor
    ->getSettings();
  if (isset($settings['plugins']['templates'])) {
    $config = $settings['plugins']['templates'];
  }
  $form['template_path'] = [
    '#title' => t('Template definition file'),
    '#type' => 'textfield',
    '#default_value' => $config['template_path'],
    '#description' => t('Path to the javascript file defining the templates, relative to drupal root (starting with "/"). By default, it looks in your default theme directory for a file named "templates/ckeditor_templates.js"'),
  ];
  $form['replace_content'] = [
    '#title' => t('Replace content default value'),
    '#type' => 'checkbox',
    '#default_value' => $config['replace_content'],
    '#description' => t('Whether the "Replace actual contents" checkbox is checked by default in the Templates dialog'),
  ];
  $form['#attached']['library'][] = 'ckeditor_templates/ckeditor.templates.admin';
  return $form;
}