You are here

public function Internal::getButtons in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal::getButtons()

Returns the buttons that this plugin provides, along with metadata.

The metadata is used by the CKEditor module to generate a visual CKEditor toolbar builder UI.

Return value

array An array of buttons that are provided by this plugin. This will only be used in the administrative section for assembling the toolbar. Each button should by keyed by its CKEditor button name, and should contain an array of button properties, including:

  • label: A human-readable, translated button name.
  • image: An image for the button to be used in the toolbar.
  • image_rtl: If the image needs to have a right-to-left version, specify an alternative file that will be used in RTL editors.
  • image_alternative: If this button does not render as an image, specify an HTML string representing the contents of this button.
  • image_alternative_rtl: Similar to image_alternative, but a right-to-left version.
  • attributes: An array of HTML attributes which should be added to this button when rendering the button in the administrative section for assembling the toolbar.
  • multiple: Boolean value indicating if this button may be added multiple times to the toolbar. This typically is only applicable for dividers and group indicators.

Overrides CKEditorPluginButtonsInterface::getButtons

File

core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php, line 128
Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal.

Class

Internal
Defines the "internal" plugin (i.e. core plugins part of our CKEditor build).

Namespace

Drupal\ckeditor\Plugin\CKEditorPlugin

Code

public function getButtons() {
  $button = function ($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,
      ],
    ];
  };
  return array(
    // "basicstyles" plugin.
    'Bold' => array(
      'label' => t('Bold'),
      'image_alternative' => $button('bold'),
      'image_alternative_rtl' => $button('bold', 'rtl'),
    ),
    'Italic' => array(
      'label' => t('Italic'),
      'image_alternative' => $button('italic'),
      'image_alternative_rtl' => $button('italic', 'rtl'),
    ),
    'Underline' => array(
      'label' => t('Underline'),
      'image_alternative' => $button('underline'),
      'image_alternative_rtl' => $button('underline', 'rtl'),
    ),
    'Strike' => array(
      'label' => t('Strike-through'),
      'image_alternative' => $button('strike'),
      'image_alternative_rtl' => $button('strike', 'rtl'),
    ),
    'Superscript' => array(
      'label' => t('Superscript'),
      'image_alternative' => $button('super script'),
      'image_alternative_rtl' => $button('super script', 'rtl'),
    ),
    'Subscript' => array(
      'label' => t('Subscript'),
      'image_alternative' => $button('sub script'),
      'image_alternative_rtl' => $button('sub script', 'rtl'),
    ),
    // "removeformat" plugin.
    'RemoveFormat' => array(
      'label' => t('Remove format'),
      'image_alternative' => $button('remove format'),
      'image_alternative_rtl' => $button('remove format', 'rtl'),
    ),
    // "justify" plugin.
    'JustifyLeft' => array(
      'label' => t('Align left'),
      'image_alternative' => $button('justify left'),
      'image_alternative_rtl' => $button('justify left', 'rtl'),
    ),
    'JustifyCenter' => array(
      'label' => t('Align center'),
      'image_alternative' => $button('justify center'),
      'image_alternative_rtl' => $button('justify center', 'rtl'),
    ),
    'JustifyRight' => array(
      'label' => t('Align right'),
      'image_alternative' => $button('justify right'),
      'image_alternative_rtl' => $button('justify right', 'rtl'),
    ),
    'JustifyBlock' => array(
      'label' => t('Justify'),
      'image_alternative' => $button('justify block'),
      'image_alternative_rtl' => $button('justify block', 'rtl'),
    ),
    // "list" plugin.
    'BulletedList' => array(
      'label' => t('Bullet list'),
      'image_alternative' => $button('bulleted list'),
      'image_alternative_rtl' => $button('bulleted list', 'rtl'),
    ),
    'NumberedList' => array(
      'label' => t('Numbered list'),
      'image_alternative' => $button('numbered list'),
      'image_alternative_rtl' => $button('numbered list', 'rtl'),
    ),
    // "indent" plugin.
    'Outdent' => array(
      'label' => t('Outdent'),
      'image_alternative' => $button('outdent'),
      'image_alternative_rtl' => $button('outdent', 'rtl'),
    ),
    'Indent' => array(
      'label' => t('Indent'),
      'image_alternative' => $button('indent'),
      'image_alternative_rtl' => $button('indent', 'rtl'),
    ),
    // "undo" plugin.
    'Undo' => array(
      'label' => t('Undo'),
      'image_alternative' => $button('undo'),
      'image_alternative_rtl' => $button('undo', 'rtl'),
    ),
    'Redo' => array(
      'label' => t('Redo'),
      'image_alternative' => $button('redo'),
      'image_alternative_rtl' => $button('redo', 'rtl'),
    ),
    // "blockquote" plugin.
    'Blockquote' => array(
      'label' => t('Blockquote'),
      'image_alternative' => $button('blockquote'),
      'image_alternative_rtl' => $button('blockquote', 'rtl'),
    ),
    // "horizontalrule" plugin
    'HorizontalRule' => array(
      'label' => t('Horizontal rule'),
      'image_alternative' => $button('horizontal rule'),
      'image_alternative_rtl' => $button('horizontal rule', 'rtl'),
    ),
    // "clipboard" plugin.
    'Cut' => array(
      'label' => t('Cut'),
      'image_alternative' => $button('cut'),
      'image_alternative_rtl' => $button('cut', 'rtl'),
    ),
    'Copy' => array(
      'label' => t('Copy'),
      'image_alternative' => $button('copy'),
      'image_alternative_rtl' => $button('copy', 'rtl'),
    ),
    'Paste' => array(
      'label' => t('Paste'),
      'image_alternative' => $button('paste'),
      'image_alternative_rtl' => $button('paste', 'rtl'),
    ),
    // "pastetext" plugin.
    'PasteText' => array(
      'label' => t('Paste Text'),
      'image_alternative' => $button('paste text'),
      'image_alternative_rtl' => $button('paste text', 'rtl'),
    ),
    // "pastefromword" plugin.
    'PasteFromWord' => array(
      'label' => t('Paste from Word'),
      'image_alternative' => $button('paste from word'),
      'image_alternative_rtl' => $button('paste from word', 'rtl'),
    ),
    // "specialchar" plugin.
    'SpecialChar' => array(
      'label' => t('Character map'),
      'image_alternative' => $button('special char'),
      'image_alternative_rtl' => $button('special char', 'rtl'),
    ),
    'Format' => array(
      'label' => t('HTML block format'),
      'image_alternative' => [
        '#type' => 'inline_template',
        '#template' => '<a href="#" role="button" aria-label="{{ format_text }}"><span class="ckeditor-button-dropdown">{{ format_text }}<span class="ckeditor-button-arrow"></span></span></a>',
        '#context' => [
          'format_text' => t('Format'),
        ],
      ],
    ),
    // "table" plugin.
    'Table' => array(
      'label' => t('Table'),
      'image_alternative' => $button('table'),
      'image_alternative_rtl' => $button('table', 'rtl'),
    ),
    // "showblocks" plugin.
    'ShowBlocks' => array(
      'label' => t('Show blocks'),
      'image_alternative' => $button('show blocks'),
      'image_alternative_rtl' => $button('show blocks', 'rtl'),
    ),
    // "sourcearea" plugin.
    'Source' => array(
      'label' => t('Source code'),
      'image_alternative' => $button('source'),
      'image_alternative_rtl' => $button('source', 'rtl'),
    ),
    // "maximize" plugin.
    'Maximize' => array(
      'label' => t('Maximize'),
      'image_alternative' => $button('maximize'),
      'image_alternative_rtl' => $button('maximize', 'rtl'),
    ),
    // No plugin, separator "button" for toolbar builder UI use only.
    '-' => array(
      'label' => t('Separator'),
      'image_alternative' => [
        '#type' => 'inline_template',
        '#template' => '<a href="#" role="button" aria-label="{{ button_separator_text }}" class="ckeditor-separator"></a>',
        '#context' => [
          'button_separator_text' => t('Button separator'),
        ],
      ],
      'attributes' => array(
        'class' => array(
          'ckeditor-button-separator',
        ),
        'data-drupal-ckeditor-type' => 'separator',
      ),
      'multiple' => TRUE,
    ),
  );
}