public function CodeSnippet::settingsForm in CKEditor CodeSnippet 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/ CodeSnippet.php, line 68
Class
- CodeSnippet
- Defines the "codesnippet" plugin.
Namespace
Drupal\codesnippet\Plugin\CKEditorPluginCode
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor
->getSettings();
$styles = $this
->getStyles();
$languages = $this
->getLanguages();
natcasesort($languages);
$form['#attached']['library'][] = 'codesnippet/codesnippet.admin';
$form['highlight_style'] = [
'#type' => 'select',
'#title' => 'highlight.js Style',
'#description' => $this
->t('Select a style to apply to all highlighted code snippets. You can preview the styles at <a href=":url">:url</a>.', [
':url' => 'https://highlightjs.org/static/demo',
]),
'#options' => $styles,
'#default_value' => !empty($settings['plugins']['codesnippet']['highlight_style']) ? $settings['plugins']['codesnippet']['highlight_style'] : $this
->getDefaultStyle(),
];
$form['highlight_languages'] = [
'#type' => 'checkboxes',
'#title' => 'Supported Languages',
'#options' => $languages,
'#description' => $this
->t('Enter languages you want to have as options in the editor dialog. To add a language not in this list, please see the README.txt of this module.'),
'#default_value' => isset($settings['plugins']['codesnippet']['highlight_languages']) ? $settings['plugins']['codesnippet']['highlight_languages'] : $this
->getDefaultLanguages(),
];
return $form;
}