function Internal::getButtons

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

Overrides CKEditorPluginButtonsInterface::getButtons

File

core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php, line 129

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.