1

I am using hook_editor_js_settings_alter() to disallow HTML tags in Ckeditor. It is only working in node edit form, and Ckeditor is in edit mode. Wen I preview the published page it allows the tags in my disallow custom hook.

The following code was a test to disallow <h1> tags with the class name myHeader2. If I change the class name to myheader, it work in edit mode and published mode. Is the class name the problem?

use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;

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

1 Answer 1

0

Navigate to /admin/config/content/formats. For each text format, you can enable the Limit allowed HTML tags and correct faulty HTML filter, which is configurable with the Allowed HTML tags text box at the bottom of the configuration form.

This is how input formats are supposed to be changed.

3
  • 1
    I am also using the allowed html in the GUI. Inside I have <h1 class>. This will allow h1 to have any class. But I also want to disallow the h1 class "myHeader2". So I am using the hook to do it. Aug 28, 2018 at 17:29
  • 1
    From the help for the Allowed HTML tags field: Each attribute may allow all values, or only allow specific values. So, it seems like you should be able to white-list specific values this way as well. Aug 28, 2018 at 17:33
  • How can I allow an h1 to have any attribute, class and style. There are too many to list right? I could do this <h1 id name href hreflang title class> But It may still be missing some attribute. Can I do it with a wildcard like this <h1 > I like the way the custom hook will allow all like this h1[]{}() the 3 brackets allow all attributes, style and class names. Aug 28, 2018 at 20:42

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