1 ckeditor5.api.php hook_ckeditor5_plugins()

Provides a list of CKEditor plugins.

Each plugin for CKEditor must provide an array of properties containing information about the plugin. Available properties for each plugin include:

  • library: An array specifying the module and library key provided by hook_library_info(). Each plugin should provide a library to define its JS and CSS files.
  • enabled_callback: String containing a function name that can determine if this plugin should be enabled based on the current editor configuration. See the hook_ckeditor5_PLUGIN_plugin_check() function for an example. This can also be set to the boolean TRUE to always enable a plugin.
  • pseudo_plugin: Optional. Boolean indicating this entry is not a real plugin that needs to be loaded. This can be used to provide additional default configuration with an enabled_callback.
  • plugin_dependencies: An array of other plugin names on which this button depends. Note dependencies can also be specified on a per-button basis within the "buttons" property.
  • buttons: An array of buttons that are provided by this plugin. Each button should be 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. This alternative will only be used in the administrative section for assembling the toolbar.
    • 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.
    • required_html: If this button requires certain HTML tags or attributes to be allowed, specify an array for each set of tags that should be allowed. For example:
    array(
      '<a href alt class="external internal">'
    );
    

Note this differs from the CKEditor 4 configuration, which used a nested array.

  • plugin_dependencies: An array of other plugin names on which this button depends. This can be useful if this plugin provides multiple buttons. If this plugin always has a dependency regardless of the buttons used, specify plugin_dependencies at the plugin level.
  • optional_html: If this button can work with or without certain tags or attributes in a reduced manner, then specify additional values that can be used to provide the full functionality. This should match the same format as the "required_html" return value.

Return value

array: An array of plugin definitions, keyed by the plugin name.

See also

ckeditor5_ckeditor5_plugins()

hook_ckeditor5_PLUGIN_plugin_check()

Related topics

File

core/modules/ckeditor5/ckeditor5.api.php, line 73
Documentation for CKEditor module APIs.

Code

function hook_ckeditor5_plugins() {
  $plugins['myPlugin.MyPlugin'] = array(
    'library' => array('my_module', 'my_module.ckeditor5.myplugin'),
    'css' => array(backdrop_get_path('module', 'my_module') . '/css/myplugin.css'),
    'enabled_callback' => 'my_module_myplugin_plugin_check',
    'buttons' => array(
      'myButton' => array(
        'library' => array('my_module', 'my-module-ckeditor5-plugin'),
        'label' => t('My custom button'),
        'required_html' => array(
          '<a href alt class="external internal">',
        ),
      ),
    ),
  );

  return $plugins;
}