I'd like to customise the CKEditor config, by using the removePlugins setting to disable the elementspath plugin, so that body p etc. isn't displayed in the status bar (here's a similar, old question for D7).

I created the following CKEditor plugin, which returns an additional setting via the getConfig() method. It has no effect on my editor fields (I've verified the plugin ID is being matched).

What's the right approach - if not this - for a config change, given I'm not loading a new plugin JS file or adding buttons?

<?php

/**
 * @file
 * Definition of \Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin\RemoveElementsPath
 */

namespace Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin;

use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\editor\Entity\Editor;

/**
 * Defines the "Remove Elements Path" plugin.
 *
 * @CKEditorPlugin(
 *   id = "remove_elements_path",
 *   label = @Translation("Remove elements path"),
 *   module = "ckeditor_remove_elementspath"
 * )
 */
class RemoveElementsPath extends Pluginbase implements CKEditorPluginInterface {

  /**
   * {@inheritdoc}
   */
  function getDependencies(Editor $editor) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  function getLibraries(Editor $editor) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return [ ];
  }

  public function getConfig(Editor $editor) {
    return [
      'removePlugins' => 'elementspath',
    ];
  }

}

I had a look at the CKEditor API docs and the other classes I might extend - it didn't seem to be any of:

  • CKEditorPluginButtonsInterface
  • CKEditorPluginContextualInterface
  • CKEditorPluginCssInterface

…though perhaps CKEditorPluginConfigurableInterface, if I wanted to configure the settings form per text format?

Then, I found a module called ckeditor_config, so I adapted it's plugin class, which extends CKEditorPlugin/Internal:

/**
 * @file
 * Definition of \Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin\RemoveElementsPath
 */

namespace Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin;

use Drupal\ckeditor\Plugin\CKEditorPlugin\Internal;
use Drupal\editor\Entity\Editor;

/**
 * Defines the "Remove Elements Path" plugin.
 *
 * @CKEditorPlugin(
 *   id = "remove_elements_path",
 *   label = @Translation("Remove elements path from CKEditor status bar")
 * )
 */
class RemoveElementsPath extends Internal {

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    // Get default config.
    $config = parent::getConfig($editor);

    $config['removePlugins'] = 'elementspath';

    return $config;
  }

}

Edit: And here's my module if anyone finds it useful.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.