class DrupalSpecialChars in CKEditor Special Characters 8
Defines the "specialChars" plugin.
Plugin annotation
@CKEditorPlugin(
id = "specialchars",
label = @Translation("Special characters"),
module = "ckeditor"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\ckeditor_specialchars\Plugin\CKEditorPlugin\DrupalSpecialChars implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DrupalSpecialChars
File
- src/
Plugin/ CKEditorPlugin/ DrupalSpecialChars.php, line 20
Namespace
Drupal\ckeditor_specialchars\Plugin\CKEditorPluginView source
class DrupalSpecialChars extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface {
/**
* Default characters to use.
*
* Copied from CKEDITOR.config.specialChars in
* file core/assets/vendor/ckeditor/plugins/specialchar/plugin.js.
*
* @var array
*/
public $defaultCharacters = [
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
']',
'^',
'_',
'`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'{',
'|',
'}',
'~',
'€',
'‘',
'’',
'“',
'”',
'–',
'—',
'¡',
'¢',
'£',
'¤',
'¥',
'¦',
'§',
'¨',
'©',
'ª',
'«',
'¬',
'®',
'¯',
'°',
'²',
'³',
'´',
'µ',
'¶',
'·',
'¸',
'¹',
'º',
'»',
'¼',
'½',
'¾',
'¿',
'À',
'Á',
'Â',
'Ã',
'Ä',
'Å',
'Æ',
'Ç',
'È',
'É',
'Ê',
'Ë',
'Ì',
'Í',
'Î',
'Ï',
'Ð',
'Ñ',
'Ò',
'Ó',
'Ô',
'Õ',
'Ö',
'×',
'Ø',
'Ù',
'Ú',
'Û',
'Ü',
'Ý',
'Þ',
'ß',
'à',
'á',
'â',
'ã',
'ä',
'å',
'æ',
'ç',
'è',
'é',
'ê',
'ë',
'ì',
'í',
'î',
'ï',
'ð',
'ñ',
'ò',
'ó',
'ô',
'õ',
'ö',
'÷',
'ø',
'ù',
'ú',
'û',
'ü',
'ý',
'þ',
'ÿ',
'Œ',
'œ',
'Ŵ',
'Ŷ',
'ŵ',
'ŷ',
'‚',
'‛',
'„',
'…',
'™',
'►',
'•',
'→',
'⇒',
'⇔',
'♦',
'≈',
];
/**
* {@inheritdoc}
*/
public function isInternal() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function isEnabled(Editor $editor) {
$settings = $editor
->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'SpecialChar') {
return TRUE;
}
}
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getFile() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
// Defaults.
$config = [
'characters' => '',
'replace' => FALSE,
];
$settings = $editor
->getSettings();
if (isset($settings['plugins']['specialchars'])) {
$config = $settings['plugins']['specialchars'];
}
$characters = explode("\n", $config['characters']);
$characters = array_map('trim', $characters);
$characters = array_filter($characters, 'strlen');
// Not replace = append.
if (!$config['replace']) {
$characters = array_merge($this->defaultCharacters, $characters);
}
return [
'specialChars' => $characters,
];
}
/**
* {@inheritdoc}
*/
public function getButtons() {
return [
'SpecialChar' => [
'label' => $this
->t('Character map'),
'image_alternative' => $this
->buttonTemplate('special char'),
'image_alternative_rtl' => $this
->buttonTemplate('special char', 'rtl'),
],
];
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Defaults.
$config = [
'characters' => '',
'replace' => FALSE,
];
$settings = $editor
->getSettings();
if (isset($settings['plugins']['specialchars'])) {
$config = $settings['plugins']['specialchars'];
}
$form['characters'] = [
'#type' => 'textarea',
'#title' => $this
->t('Special characters'),
'#description' => $this
->t('One per line'),
'#default_value' => $config['characters'],
];
$form['replace'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Replace default characters?'),
'#description' => $this
->t('Leaving un-checked will append to default character list.'),
'#default_value' => $config['replace'],
];
return $form;
}
/**
* CKEditor button template.
*
* @param string $name
* Button name.
* @param string $direction
* Language direction.
*
* @return array
* Renderable array.
*
* @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal::getButtons()
*/
protected function buttonTemplate($name, $direction = 'ltr') {
// In the markup below, we mostly use the name (which may include spaces),
// but in one spot we use it as a CSS class, so strip spaces.
// Note: this uses str_replace() instead of Html::cleanCssIdentifier()
// because we must provide these class names exactly how CKEditor expects
// them in its library, which cleanCssIdentifier() does not do.
$class_name = str_replace(' ', '', $name);
return [
'#type' => 'inline_template',
'#template' => '<a href="#" class="cke-icon-only cke_{{ direction }}" role="button" title="{{ name }}" aria-label="{{ name }}"><span class="cke_button_icon cke_button__{{ classname }}_icon">{{ name }}</span></a>',
'#context' => [
'direction' => $direction,
'name' => $name,
'classname' => $class_name,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CKEditorPluginBase:: |
public | function |
Returns a list of plugins this plugin requires. Overrides CKEditorPluginInterface:: |
1 |
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 | |
DrupalSpecialChars:: |
public | property | Default characters to use. | |
DrupalSpecialChars:: |
protected | function | CKEditor button template. | |
DrupalSpecialChars:: |
public | function |
Returns the buttons that this plugin provides, along with metadata. Overrides CKEditorPluginButtonsInterface:: |
|
DrupalSpecialChars:: |
public | function |
Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface:: |
|
DrupalSpecialChars:: |
public | function |
Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface:: |
|
DrupalSpecialChars:: |
public | function |
Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase:: |
|
DrupalSpecialChars:: |
public | function |
Checks if this plugin should be enabled based on the editor configuration. Overrides CKEditorPluginContextualInterface:: |
|
DrupalSpecialChars:: |
public | function |
Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginBase:: |
|
DrupalSpecialChars:: |
public | function |
Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface:: |
|
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. |