You are here

protected function DrupalSpecialChars::buttonTemplate in CKEditor Special Characters 8

CKEditor button template.

Parameters

string $name: Button name.

string $direction: Language direction.

Return value

array Renderable array.

See also

\Drupal\ckeditor\Plugin\CKEditorPlugin\Internal::getButtons()

1 call to DrupalSpecialChars::buttonTemplate()
DrupalSpecialChars::getButtons in src/Plugin/CKEditorPlugin/DrupalSpecialChars.php
Returns the buttons that this plugin provides, along with metadata.

File

src/Plugin/CKEditorPlugin/DrupalSpecialChars.php, line 172

Class

DrupalSpecialChars
Defines the "specialChars" plugin.

Namespace

Drupal\ckeditor_specialchars\Plugin\CKEditorPlugin

Code

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,
    ],
  ];
}