8

In Drupal 7 I was able to add config rules to CKEditor in the admin (like config.allowedContent = true; for example). I can't find this option in Drupal 8. Is it possible to do something similar?

10
+50

In regards to "allowedContent", this is set to true if you don't check "Limit allowed HTML tags and correct faulty HTML"( or another filter of type of FilterInterface::TYPE_HTML_RESTRICTOR) on your text format, otherwise it outputs the tags you have added there.

enter image description here

For more info on this, you can view:

ckeditor/src/Plugin/CKEditorPlugin/Internal:getConfig()

and

ckeditor/src/Plugin/CKEditorPlugin/Internal:generateACFSettings()

If wanted to override the Internal:getConfig method, you could create a new class that extends it and then replace the class using hook_ckeditor_plugin_info_alter().

function mymodule_ckeditor_plugin_info_alter(array &$plugins) {
  $plugins['internal']['class'] = 'Drupal\mymodule\Plugins\CKEditorPlugin\CustomInternal';
}

And then your custom override class:

<?php

namespace Drupal\mymodule\Plugins\CKEditorPlugin;

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

/**
 * Allow custom config settings.
 *
 * @CKEditorPlugin(
 *   id = "custom_internal",
 *   label = @Translation("Custom CKEditor core")
 * )
 */
class CustomInternal extends Internal {

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {

    $config = parent::getConfig($editor);

    // Put your custom configs here.
    $config['allowedContent'] = TRUE;

    return $config;
  }

}
  • where do you add the custom override class? – aydow Jul 11 '18 at 5:26
  • in your custom module, in src/Plugins/CKEditor would be a good place – oknate Jul 11 '18 at 10:11
4

Sorry to add this as an answer. I'll try to move it to a comment as soon as I've got enough "Drupal 8 Stack Exchange Cred" to comment (*ugh* reputation *grumbles*)

OP: Did you ever get an answer on whether there is any module or easy way to add this "CKEditor Advanced Configuration" field back in to Drupal 8's text filter settings page? Drupal 7 had it - and it's a super useful thing. Drupal 8 seems to have regressed in this regard :/

I've searched high and low and it seems no one has implemented anything to return this option to text formats in Drupal 8.

There is a module called CKEditor Config, which comes close ( https://www.drupal.org/project/ckeditor_config ), but it only allows overriding CKEditor configuration globally (for all text profiles).

If there's nothing else out there, I'll try posting an issue asking the author of that module if he would consider adding support for per-text format configuration (or look into adding it myself one day). It seems that everyone else has opted for the approach of overriding CKEditor configuration with various hook implementations in custom modules, but an "advanced configuration" field would be a valuable time-saver now, considering Drupal 8's snazzy config management abilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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