1 ckeditor5.module ckeditor5_ckeditor5_plugins()

Implements hook_ckeditor5_plugins().

Return a list of all plugins provided by this module.

File

core/modules/ckeditor5/ckeditor5.module, line 269
Provides integration with the CKEditor WYSIWYG editor.

Code

function ckeditor5_ckeditor5_plugins() {
  $image_prefix = backdrop_get_path('module', 'ckeditor5') . '/icons';

  // The "essentials" plugin is necessary for any kind of basic editing. Basic
  // formatting buttons are included under this plugin, even though they are
  // not technically provided by it.
  $plugins['essentials.Essentials'] = array(
    'buttons' => array(
      // Provided by the basic-styles plugin.
      // @see https://ckeditor.com/docs/ckeditor5/latest/features/basic-styles.html
      'bold' => array(
        'label' => t('Bold'),
        'image' => $image_prefix . '/bold.svg',
        'required_html' => array('<strong>'),
        'plugin_dependencies' => array('basicStyles.Bold'),
      ),
      'italic' => array(
        'label' => t('Italic'),
        'image' => $image_prefix . '/italic.svg',
        // CKEditor defaults to <i>, the BackdropBasicStyles plugin converts it
        // to <em> for backwards-compatibility with Backdrop standards.
        'required_html' => array('<em>'),
        'plugin_dependencies' => array(
          'basicStyles.Italic',
          'backdropBasicStyles.BackdropBasicStyles',
        ),
      ),
      'underline' => array(
        'label' => t('Underline'),
        'image' => $image_prefix . '/underline.svg',
        // Unlike CKEditor 4, we conform to CKEditor 5's preference for the <u>
        // tag for underlined content. The BackdropBasicStyles plugin converts
        // legacy <span class="underline"> content to use <u>.
        'required_html' => array('<u>'),
        'plugin_dependencies' => array(
          'basicStyles.Underline',
          'backdropBasicStyles.BackdropBasicStyles',
        ),
      ),
      'strikethrough' => array(
        'label' => t('Strike-through'),
        'image' => $image_prefix . '/strikethrough.svg',
        // CKEditor defaults to <s>, the BackdropBasicStyles plugin converts it
        // to <del> for backwards-compatibility with Backdrop standards.
        'required_html' => array('<del>'),
        'plugin_dependencies' => array(
          'basicStyles.Strikethrough',
          'backdropBasicStyles.BackdropBasicStyles',
        ),
      ),
      'code' => array(
        'label' => t('Code'),
        'image' => $image_prefix . '/code.svg',
        'required_html' => array('<code>'),
        'plugin_dependencies' => array('basicStyles.Code'),
      ),
      'subscript' => array(
        'label' => t('Subscript'),
        'image' => $image_prefix . '/subscript.svg',
        'required_html' => array('<sub>'),
        'plugin_dependencies' => array('basicStyles.Subscript'),
      ),
      'superscript' => array(
        'label' => t('Superscript'),
        'image' => $image_prefix . '/superscript.svg',
        'required_html' => array('<sup>'),
        'plugin_dependencies' => array('basicStyles.Superscript'),
      ),
      // Separator, part of toolbar core.
      // @see https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#separating-toolbar-items
      '|' => array(
        'label' => t('Separator'),
        'image_alternative' => '<span class="ckeditor5-separator" title="' . t('Button separator') . '" aria-label="' . t('Button separator') . '">&nbsp;</span>',
        'attributes' => array('class' => array('ckeditor5-button-separator')),
        'multiple' => TRUE,
      ),
      // Line break, part of toolbar core.
      // @see https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#multiline-wrapping-toolbar
      '-' => array(
        'label' => t('Line Break'),
        'image_alternative' => '<span class="ckeditor5-line-break" title="' . t('Line break') . '" aria-label="' . t('Line break') . '">&nbsp;</span>',
        'multiple' => TRUE,
      ),
    ),
    'enabled_callback' => TRUE,
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/text-alignment.html
  $plugins['alignment.Alignment'] = array(
    'buttons' => array(
      'alignment' => array(
        'label' => t('Alignment'),
        'image_alternative' => '<span class="ckeditor5-button-dropdown">' . t('Alignment') . '<span class="ckeditor5-button-arrow"></span></span>',
        'required_html' => array('<p class="text-align-left text-align-center text-align-right text-align-justify">'),
      ),
      'alignment:left' => array(
        'label' => t('Align left'),
        'image' => $image_prefix . '/align-left.svg',
        'required_html' => array('<p class="text-align-left">'),
      ),
      'alignment:center' => array(
        'label' => t('Align center'),
        'required_html' => array('<p class="text-align-center">'),
        'image' => $image_prefix . '/align-center.svg',
      ),
      'alignment:right' => array(
        'label' => t('Align right'),
        'required_html' => array('<p class="text-align-right">'),
        'image' => $image_prefix . '/align-right.svg',
      ),
      'alignment:justify' => array(
        'label' => t('Justify'),
        'required_html' => array('<p class="text-align-justify">'),
        'image' => $image_prefix . '/align-justify.svg',
      ),
    ),
    'plugin_dependencies' => array('alignment.Alignment'),
    'config' => array(
      'alignment' => array(
        'options' => array(
          array('name' => 'left', 'className' => 'text-align-left'),
          array('name' => 'center', 'className' => 'text-align-center'),
          array('name' => 'right', 'className' => 'text-align-right'),
          array('name' => 'justify', 'className' => 'text-align-justify'),
        ),
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/indent.html
  $plugins['indent.Indent'] = array(
    'buttons' => array(
      'indent' => array(
        'label' => t('Indent'),
        'image' => $image_prefix . '/indent.svg',
        'required_html' => array('<p class="indent1 indent2 indent3">'),
      ),
      'outdent' => array(
        'label' => t('Outdent'),
        'image' => $image_prefix . '/outdent.svg',
        'required_html' => array('<p class="indent1 indent2 indent3">'),
      ),
    ),
    'plugin_dependencies' => array('list.DocumentList'),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/lists/document-lists.html
  $plugins['list.DocumentList'] = array(
    'buttons' => array(
      'bulletedList' => array(
        'label' => t('Bullet list'),
        'image' => $image_prefix . '/bulleted-list.svg',
        'image_rtl' => $image_prefix . '/bulleted-list-rtl.svg',
        'required_html' => array('<ul>', '<li>'),
      ),
      'numberedList' => array(
        'label' => t('Numbered list'),
        'image' => $image_prefix . '/numbered-list.svg',
        'image_rtl' => $image_prefix . '/numbered-list-rtl.svg',
        'required_html' => array('<ol>', '<li>'),
      ),
    ),
    // Re-specify list.DocumentList as its own dependency to ensure it loads
    // before list.DocumentListProperties, otherwise list properties will not
    // show in the UI.
    'plugin_dependencies' => array(
      'list.DocumentList',
      'list.DocumentListProperties',
    ),
    'config' => array(
      'list' => array(
        'properties' => array(
          'reversed' => TRUE,
          'startIndex' => TRUE,
          'styles' => FALSE,
        ),
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html
  $plugins['codeBlock.CodeBlock'] = array(
    'buttons' => array(
      'codeBlock' => array(
        'label' => t('Code block'),
        'image' => $image_prefix . '/code-block.svg',
        'required_html' => array('<code>', '<pre>'),
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/block-quote.html
  $plugins['blockQuote.BlockQuote'] = array(
    'buttons' => array(
      'blockQuote' => array(
        'label' => t('Block quote'),
        'image' => $image_prefix . '/block-quote.svg',
        'required_html' => array('<blockquote>'),
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/source-editing.html
  $plugins['sourceEditing.SourceEditing'] = array(
    'buttons' => array(
      'sourceEditing' => array(
        'label' => t('Source'),
        'image' => $image_prefix . '/source-editing.svg',
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/horizontal-line.html
  $plugins['horizontalLine.HorizontalLine'] = array(
    'buttons' => array(
      'horizontalLine' => array(
        'label' => t('Horizontal line'),
        'image' => $image_prefix . '/horizontal-line.svg',
        'required_html' => array('<hr>'),
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/remove-format.html
  $plugins['removeFormat.RemoveFormat'] = array(
    'buttons' => array(
      'removeFormat' => array(
        'label' => t('Remove format'),
        'image' => $image_prefix . '/remove-format.svg',
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/autoformat.html
  $plugins['autoformat.Autoformat'] = array(
    // @todo: Provide a configuration option to toggle.
    'enabled_callback' => TRUE,
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/pasting/paste-from-google-docs.html
  $plugins['pasteFromOffice.PasteFromOffice'] = array(
    // @todo: Provide a configuration option to toggle.
    'enabled_callback' => TRUE,
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/tables/tables.html
  $plugins['table.Table'] = array(
    'buttons' => array(
      'insertTable' => array(
        'label' => t('Table'),
        'image' => $image_prefix . '/table.svg',
        'required_html' => array(
          '<table>',
          '<td rowspan colspan>',
          '<th rowspan colspan>',
          '<tr>',
          '<thead>',
          '<tbody>',
          '<tfoot>',
          '<caption>',
        ),
      ),
    ),
    'plugin_dependencies' => array(
      'table.TableToolbar',
      'table.TableCaption',
      'table.PlainTableOutput',
      'table.TableCellProperties',
      'table.TableColumnResize',
      'table.TableProperties',
    ),
    'config' => array(
      'table' => array(
        'contentToolbar' => array(
          'tableColumn',
          'tableRow',
          'mergeTableCells',
          'toggleTableCaption',
        ),
      ),
    ),
  );

  // Paragraph is always enabled in Backdrop to ensure text can be added in case
  // the Headings are not enabled.
  $plugins['paragraph.Paragraph'] = array(
    'enabled_callback' => TRUE,
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/headings.html
  $plugins['heading.Heading'] = array(
    'buttons' => array(
      'heading' => array(
        'label' => t('Headings'),
        'image_alternative' => '<span class="ckeditor5-button-dropdown">' . t('Headings') . '<span class="ckeditor5-button-arrow"></span></span>',
      ),
    ),
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/style.html
  $plugins['style.Style'] = array(
    'buttons' => array(
      'style' => array(
        'label' => t('Font style'),
        'image_alternative' => '<span class="ckeditor5-button-dropdown">' . t('Styles') . '<span class="ckeditor5-button-arrow"></span></span>',
        'plugin_dependencies' => array('htmlSupport.GeneralHtmlSupport'),
      ),
    ),
  );

  // General HTML support is always enabled in Backdrop to provide compatibility
  // with existing content and to preserve otherwise unsupported HTML tags.
  $plugins['htmlSupport.GeneralHtmlSupport'] = array(
    'enabled_callback' => TRUE,
  );

  // @see https://ckeditor.com/docs/ckeditor5/latest/features/special-characters.html
  $plugins['specialCharacters.SpecialCharacters'] = array(
    'buttons' => array(
      'specialCharacters' => array(
        'label' => t('Special characters'),
        'image' => $image_prefix . '/special-characters.svg',
        'plugin_dependencies' => array('specialCharacters.SpecialCharactersEssentials'),
      ),
    ),
  );

  // Plugin that converts CKEditor preferred tags to Backdrop preferred tags,
  // such as converting <s> to <del> or <i> to <em>.
  $plugins['backdropBasicStyles.BackdropBasicStyles'] = array(
    'library' => array('ckeditor5', 'backdrop.ckeditor5.backdrop-basic-styles'),
    'enabled_callback' => TRUE,
  );

  // Plugin that writes the HTML source when saving the editor contents. This
  // properly escapes HTML attributes and formats the HTML source.
  $plugins['backdropHtmlEngine.BackdropHtmlEngine'] = array(
    'library' => array('ckeditor5', 'backdrop.ckeditor5.backdrop-html-engine'),
    'enabled_callback' => TRUE,
  );

  // The BackdropImage plugin extends the default CKEditor Image plugin.
  $plugins['backdropImage.BackdropImage'] = array(
    'library' => array('ckeditor5', 'backdrop.ckeditor5.backdrop-image'),
    'buttons' => array(
      'backdropImage' => array(
        'label' => t('Image'),
        'plugin_dependencies' => array(
          'image.Image',
          'image.ImageToolbar',
          'image.ImageInsertUI',
          'image.ImageUpload',
          'image.ImageResize',
          'image.ImageCaptionUtils',
        ),
        'required_html' => array(
          '<img src alt height width data-file-id>',
        ),
        'image' => $image_prefix . '/image.svg',
      ),
    ),
    'config' => array(
      'image' => array(
        // Configure the balloon toolbar items shown when an image is selected.
        'toolbar' => array(
          'imageTextAlternative',
          'editBackdropImage',
        ),
        'upload' => array(
          'type' => image_get_supported_extensions(),
        ),
        'resizeUnit' => 'px',
      ),
      'backdropImage' => array(
        'editLabel' => t('Edit Image'),
        'insertLabel' => t('Insert Image'),
        // Specify an array of CKEditor model name => attribute name values.
        // These attributes are then allowed to be changed via the Backdrop
        // image dialog. Additional attributes can be added here to prevent
        // CKEditor from striping out attributes on img tags.
        'extraAttributes' => array(
          'dataFileId' => 'data-file-id',
          'alt' => 'alt',
          'src' => 'src',
          'width' => 'width',
          'height' => 'height',
        ),
      ),
    ),
  );

  // The BackdropImageCaption plugin provides configuration only. It enables
  // converting data-caption attributes on img tags to figure and figcaption
  // elements.
  $plugins['backdropImageCaption.BackdropImageCaption'] = array(
    'pseudo_plugin' => TRUE,
    'enabled_callback' => '_ckeditor5_image_caption_plugin_check',
    'required_html' => array(
      '<img data-caption>',
      '<figure>',
      '<figcaption>',
    ),
    // The BackdropImage plugin builds on CKEditor's ImageCaptionEditing plugin.
    'plugin_dependencies' => array('image.ImageCaption'),
    'config' => array(
      'image' => array(
        'toolbar' => array(
          'toggleImageCaption',
        ),
      ),
      'backdropImage' => array(
        'captionFilterEnabled' => TRUE,
        'captionPlaceholderText' => t('Enter caption text here.'),
        'extraAttributes' => array(
          'dataCaption' => 'data-caption',
        ),
      ),
    ),
  );

  // The BackdropImageAlignment plugin provides configuration only. It enables
  // converting data-align attributes on img tags to classes.
  $plugins['backdropImage.BackdropImageAlignment'] = array(
    'pseudo_plugin' => TRUE,
    'enabled_callback' => '_ckeditor5_image_alignment_plugin_check',
    'required_html' => array(
      '<img data-align>',
    ),
    // Not to be confused with Backdrop Image Styles (provided by Image module),
    // CKEditor Image Styles are used to configure the presentation of images,
    // including alignment options.
    'plugin_dependencies' => array('image.ImageStyle'),
    'config' => array(
      'image' => array(
        // Add buttons to the balloon toolbar shown when an image is selected.
        // Note that each of these image styles are pre-defined by the
        // ImageStyle plugin.
        // See https://ckeditor.com/docs/ckeditor5/latest/features/images/images-styles.html#ready-to-use-styles
        'toolbar' => array(
          '|',
          'imageStyle:block',
          'imageStyle:alignLeft',
          'imageStyle:alignCenter',
          'imageStyle:alignRight',
          'imageStyle:inline',
          '|',
        ),
        // Configure the style buttons that were added above.
        'styles' => array(
          'options' => array(
            'inline',
            array(
              'name' => 'block',
              'icon' => 'left',
              'title' => t('Break text'),
            ),
            array(
              'name' => 'alignLeft',
              'title' => t('Align left and wrap text'),
            ),
            array(
              'name' => 'alignCenter',
              'title' => t('Align center and break text'),
            ),
            array(
              'name' => 'alignRight',
              'title' => t('Align right and wrap text'),
            ),
          ),
        ),
      ),
      'backdropImage' => array(
        'extraAttributes' => array(
          'dataAlign' => 'data-align',
        ),
      ),
    ),
  );

  // The BackdropLink plugin extends the build in link button.
  $plugins['backdropLink.BackdropLink'] = array(
    'buttons' => array(
      'backdropLink' => array(
        'label' => t('Link'),
        'image' => $image_prefix . '/link.svg',
        // @todo: The id attribute is being flagged as disallowed by core's
        // blocking of on* attributes. It should be included here.
        'required_html' => array('<a href target class title rel data-file-id>'),
        // Include a dependency on ImageUtils to help detect linked images, even
        // if the backdropImage button is not enabled.
        'plugin_dependencies' => array(
          'link.Link',
          'link.LinkUI',
          'image.ImageUtils',
        ),
      ),
    ),
    'library' => array('ckeditor5', 'backdrop.ckeditor5.backdrop-link'),
    'config' => array(
      'backdropLink' => array(
        'editLabel' => t('Edit Link'),
        'insertLabel' => t('Insert Link'),
        // Specify an array of CKEditor model name => attribute name values.
        // These attributes are then allowed to be changed via the Backdrop
        // link dialog. Additional attributes can be added here to prevent
        // CKEditor from striping out attributes on anchor tags.
        'extraAttributes' => array(
          'linkTarget' => 'target',
          'linkClass' => 'class',
          'linkTitle' => 'title',
          'linkId' => 'id',
          'linkRel' => 'rel',
          'linkDataFileId' => 'data-file-id',
        ),
      ),
    ),
  );

  // The BackdropLinkImage plugin provides configuration only. It enables
  // adds the "Link Image" button to the image balloon toolbar if both the
  // Link and Image plugins are enabled.
  $plugins['backdropLink.BackdropLinkImage'] = array(
    'pseudo_plugin' => TRUE,
    'enabled_callback' => '_ckeditor5_link_image_plugin_check',
    'plugin_dependencies' => array('link.Link', 'image.Image', 'link.LinkImage'),
    'config' => array(
      'image' => array(
        'toolbar' => array('|', 'backdropLinkImage', '|'),
      ),
    ),
  );

  $plugins['backdropMaximize.Maximize'] = array(
    'library' => array('ckeditor5', 'backdrop.ckeditor5.maximize'),
    'buttons' => array(
      'maximize' => array(
        'label' => t('Maximize'),
        'image' => $image_prefix . '/maximize.svg',
      ),
    ),
    'config' => array(
      'maximizeLabel' => t('Maximize'),
    ),
  );

  // See https://ckeditor.com/docs/ckeditor5/latest/features/undo-redo.html
  $plugins['undo.Undo'] = array(
    'buttons' => array(
      'undo' => array(
        'label' => t('Undo'),
        'image' => $image_prefix . '/undo.svg',
        'image_rtl' => $image_prefix . '/undo-rtl.svg',
      ),
      'redo' => array(
        'label' => t('Redo'),
        'image' => $image_prefix . '/redo.svg',
        'image_rtl' => $image_prefix . '/redo-rtl.svg',
      ),
    ),
  );

  // See https://ckeditor.com/docs/ckeditor5/latest/features/show-blocks.html
  $plugins['showBlocks.ShowBlocks'] = array(
    'buttons' => array(
      'showBlocks' => array(
        'label' => t('Show blocks'),
        'image' => $image_prefix . '/show-blocks.svg',
      ),
    ),
  );

  return $plugins;
}