Newer
Older
Angie Byron
committed
<?php
namespace Drupal\editor_test\Plugin\Editor;
Angie Byron
committed
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
Angie Byron
committed
use Drupal\editor\Plugin\EditorBase;
/**
* Defines a Unicorn-powered text editor for Drupal (for testing purposes).
Angie Byron
committed
*
* @Editor(
Angie Byron
committed
* id = "unicorn",
* label = @Translation("Unicorn Editor"),
* supports_content_filtering = TRUE,
* supports_inline_editing = TRUE,
* is_xss_safe = FALSE,
* supported_element_types = {
* "textarea",
* "textfield",
* }
Angie Byron
committed
* )
*/
class UnicornEditor extends EditorBase {
/**
Angie Byron
committed
* {@inheritdoc}
Angie Byron
committed
*/
function getDefaultSettings() {
return ['ponies_too' => TRUE];
Angie Byron
committed
}
/**
Angie Byron
committed
* {@inheritdoc}
Angie Byron
committed
*/
function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$form['ponies_too'] = [
Alex Pott
committed
'#title' => t('Pony mode'),
'#type' => 'checkbox',
'#default_value' => TRUE,
];
Angie Byron
committed
return $form;
}
/**
Angie Byron
committed
* {@inheritdoc}
Angie Byron
committed
*/
function getJSSettings(Editor $editor) {
$js_settings = [];
Angie Byron
committed
$settings = $editor->getSettings();
Alex Pott
committed
if ($settings['ponies_too']) {
Angie Byron
committed
$js_settings['ponyModeEnabled'] = TRUE;
Angie Byron
committed
}
Angie Byron
committed
return $js_settings;
Angie Byron
committed
}
/**
Angie Byron
committed
* {@inheritdoc}
Angie Byron
committed
*/
public function getLibraries(Editor $editor) {
return [
'editor_test/unicorn',
];