public function AceFormatter::settingsForm in Ace Code Editor 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ AceFormatter.php, line 110
Class
- AceFormatter
- Plugin implementation of the 'ace_editor' formatter.
Namespace
Drupal\ace_editor\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $formState) {
$settings = $this
->getSettings();
// $this->getSettings() returns values from defaultSettings() on first use.
// afterwards it will return the forms saved configuration.
$config = \Drupal::config('ace_editor.settings');
return [
'theme' => [
'#type' => 'select',
'#title' => t('Theme'),
'#options' => $config
->get('theme_list'),
'#attributes' => [
'style' => 'width: 150px;',
],
'#default_value' => $settings['theme'],
],
'syntax' => [
'#type' => 'select',
'#title' => t('Syntax'),
'#description' => t('The syntax that will be highlighted.'),
'#options' => $config
->get('syntax_list'),
'#attributes' => [
'style' => 'width: 150px;',
],
'#default_value' => $settings['syntax'],
],
'height' => [
'#type' => 'textfield',
'#title' => t('Height'),
'#description' => t('The height of the editor in either pixels or percents.'),
'#attributes' => [
'style' => 'width: 100px;',
],
'#default_value' => $settings['height'],
],
'width' => [
'#type' => 'textfield',
'#title' => t('Width'),
'#description' => t('The width of the editor in either pixels or percents.'),
'#attributes' => [
'style' => 'width: 100px;',
],
'#default_value' => $settings['width'],
],
'font_size' => [
'#type' => 'textfield',
'#title' => t('Font size'),
'#description' => t('The the font size of the editor.'),
'#attributes' => [
'style' => 'width: 100px;',
],
'#default_value' => $settings['font_size'],
],
'line_numbers' => [
'#type' => 'checkbox',
'#title' => t('Show line numbers'),
'#default_value' => $settings['line_numbers'],
],
'print_margins' => [
'#type' => 'checkbox',
'#title' => t('Show print margin (80 chars)'),
'#default_value' => $settings['print_margins'],
],
'show_invisibles' => [
'#type' => 'checkbox',
'#title' => t('Show invisible characters (whitespaces, EOL...)'),
'#default_value' => $settings['show_invisibles'],
],
'use_wrap_mode' => [
'#type' => 'checkbox',
'#title' => t('Toggle word wrapping'),
'#default_value' => $settings['use_wrap_mode'],
],
];
}