0

I am trying to use the Disallowed Content configuration from Ckeditor. https://docs.ckeditor.com/ckeditor4/latest/guide/dev_disallowed_content.html I am using Drupal 8.5.3 Lightning 8.x-3 and the built in Ckeditor v4.8

I have placed this js in my theme and the js is loading when I am in page edit mode.

(function ($, Drupal) {
  Drupal.behaviors.customCKEditorConfig = {
    attach: function (context, settings) {
      if (typeof CKEDITOR !== "undefined") {
        config.disallowedContent= 'div span';
      }
    }
  }
})(jQuery, Drupal);

But this is not working. I have tried with the Allowed HTML tags enabled and disabled. I got this information from these sources. http://drucafe.blogspot.com/2016/02/adding-custom-styles-to-ckeditor-in.html and https://tutel.me/c/drupal/questions/183036/allow+empty+tags and Drupal 8 CKeditor behaves LTR in an RTL site.

I have tried the filter 3 different ways

editor.filter.disallow( 'span div' );
config.disallowedContent( 'span div' );
config.disallowedContent= 'div span';
  • Are there any console errors? – Kevin May 3 '18 at 21:03
  • No I dont have any console errors. I am just using Seven as the admin theme so I place my js file inside seven and added it to the library. The js is loaded. I am using Drupal 8.5.3 Lightning 8.x-3 and the built in Ckeditor v4.8. I have tried the filter 3 different ways. editor.filter.disallow( 'span div' ); config.disallowedContent( 'span div' ); config.disallowedContent= 'div span'; – paulcap1 May 4 '18 at 10:48
  • I read that disallowedContent supersedes allowed content. And if the Advanced Content Filter is disabled than disallowedContent will not work. I dont know how to check if Advanced Content Filter is enabled. – paulcap1 May 4 '18 at 10:58
  • You should definitely have at least one console error. You don’t have a variable named config in scope in your code example – Clive May 4 '18 at 10:58
  • I just noticed a console error: ReferenceError: config is not defined – paulcap1 May 4 '18 at 11:00
0

This is working.

use Drupal\editor\Entity\Editor;

function MYMODULE_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    $settings['editor']['formats'][$name]['editorSettings']['disallowedContent'] =   
'h1 h2 h3';
  }
}

This supersedes any allowed tags in the drupal GUI. But you must enable Allowed HTML tags enabled for this to work. I took the idea from this.drupal-8-ckeditor-behaves-ltr

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.