class AceEditor in Ace Code Editor 8
Defines AceEditor as an Editor plugin.
Plugin annotation
@Editor(
id = "ace_editor",
label = "Ace Editor",
supports_content_filtering = TRUE,
supports_inline_editing = FALSE,
is_xss_safe = FALSE,
supported_element_types = {
"textarea"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\editor\Plugin\EditorBase implements EditorPluginInterface
- class \Drupal\ace_editor\Plugin\Editor\AceEditor
- class \Drupal\editor\Plugin\EditorBase implements EditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of AceEditor
File
- src/
Plugin/ Editor/ AceEditor.php, line 23
Namespace
Drupal\ace_editor\Plugin\EditorView source
class AceEditor extends EditorBase {
/**
* {@inheritdoc}
*/
public function getDefaultSettings() {
$config = \Drupal::config('ace_editor.settings')
->get();
return $config;
}
/**
* Returns a settings form to configure this text editor.
*
* @param array $settings
* An array containing form configuration.
*
* @return array
* A primary render array for the settings form.
*/
public function getForm(array $settings) {
$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 font size used in 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'],
],
'auto_complete' => [
'#type' => 'checkbox',
'#title' => t('Enable Autocomplete (Ctrl+Space'),
'#default_value' => isset($settings['auto_complete']) ? $settings['auto_complete'] : TRUE,
],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$editor = $form_state
->get('editor');
$settings = $editor
->getSettings();
$form = [];
$form['fieldset'] = [
'#type' => 'fieldset',
'#title' => t('Ace Editor Settings'),
'#collapsable' => TRUE,
];
if (array_key_exists('fieldset', $settings)) {
$form['fieldset'] = array_merge($form['fieldset'], $this
->getForm($settings['fieldset']));
}
else {
$form['fieldset'] = array_merge($form['fieldset'], $this
->getForm($settings));
}
return $form;
}
/**
* {@inheritdoc}
*/
public function settingsFormValidate(array $form, FormStateInterface $formState) {
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
// Get default ace_editor configuration.
$config = \Drupal::config('ace_editor.settings');
// Get theme and mode.
$theme = trim($editor
->getSettings()['fieldset']['theme']);
$mode = trim($editor
->getSettings()['fieldset']['syntax']);
// Check if theme and mode library exist.
$theme_exist = \Drupal::service('library.discovery')
->getLibraryByName('ace_editor', 'theme.' . $theme);
$mode_exist = \Drupal::service('library.discovery')
->getLibraryByName('ace_editor', 'mode.' . $mode);
// ace_editor/primary the basic library for ace_editor.
$libs = [
'ace_editor/primary',
];
if ($theme_exist) {
$libs[] = 'ace_editor/theme.' . $theme;
}
else {
$libs[] = 'ace_editor/theme.' . $config
->get('theme');
}
if ($mode_exist) {
$libs[] = 'ace_editor/mode.' . $mode;
}
else {
$libs[] = 'ace_editor/mode.' . $config
->get('syntax');
}
return $libs;
}
/**
* {@inheritdoc}
*/
public function getJsSettings(Editor $editor) {
// Pass settings to javascript.
return $editor
->getSettings()['fieldset'];
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AceEditor:: |
public | function |
Form constructor. Overrides EditorBase:: |
|
AceEditor:: |
public | function |
Returns the default settings for this configurable text editor. Overrides EditorBase:: |
|
AceEditor:: |
public | function | Returns a settings form to configure this text editor. | |
AceEditor:: |
public | function | ||
AceEditor:: |
public | function |
Returns libraries to be attached. Overrides EditorPluginInterface:: |
|
AceEditor:: |
public | function | ||
AceEditor:: |
public | function |
Form submission handler. Overrides EditorBase:: |
|
AceEditor:: |
public | function |
Form validation handler. Overrides EditorBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EditorPluginInterface:: |
public | function | Returns JavaScript settings to be attached. | 4 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |