UnicornEditor.php in Drupal 9
File
core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php
View source
<?php
namespace Drupal\editor_test\Plugin\Editor;
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
use Drupal\editor\Plugin\EditorBase;
class UnicornEditor extends EditorBase {
public function getDefaultSettings() {
return [
'ponies_too' => TRUE,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['ponies_too'] = [
'#title' => t('Pony mode'),
'#type' => 'checkbox',
'#default_value' => TRUE,
];
return $form;
}
public function getJSSettings(Editor $editor) {
$js_settings = [];
$settings = $editor
->getSettings();
if ($settings['ponies_too']) {
$js_settings['ponyModeEnabled'] = TRUE;
}
return $js_settings;
}
public function getLibraries(Editor $editor) {
return [
'editor_test/unicorn',
];
}
}
Classes
Name |
Description |
UnicornEditor |
Defines a Unicorn-powered text editor for Drupal (for testing purposes). |