Edit CKEditor's config programmatically I've created a Drupal 8 module that adds a custom plugin to the core's CKEditor. This plugin allows users to add tabbed content to their pages.

The problem is that the plugin adds a class to the  element it creates and CKEditor by default removes classes from most elements once you save the node.

I can change CKEditor config for Basic HTML editor (admin/config/content/formats/manage/basic_html) to allow classes in  elements by changing  to  in "Allowed HTML tags" input.

Now I would love to be able to do this programmatically somehow. How can I change the configuration for CKEditor in a Drupal module? Especially the "extraAllowedContent" config value.

The project for reference purposes can be found at https://github.com/j-vee/ckeditor_tabber
I had a similar case, i had to add a few attributes to the basic_html format in the Allowed HTML tags so it could work with the module editor_advance_link which allows the users to add title, class, id and target attributes to the a tag when using the core's CKEditor.

So this is what i did with some code i found here ( https://www.drupal.org/files/issues/allow_image_style_to_be-2061377-224.patch)

if ($filter = FilterFormat::load('basic_html')) {
    if (($filter_html = $filter-&gt;filters('filter_html')) &amp;&amp; $filter_html-&gt;status) {
      $config = $filter_html-&gt;getConfiguration();
      $allowed_html = !empty($config['settings']['allowed_html']) ? $config['settings']['allowed_html'] : NULL;
      $matches = [];
      if ($allowed_html &amp;&amp; preg_match('/&lt;a ([^&gt;]*)&gt;/', $allowed_html, $matches)) {
        $new_attributes = array_filter(explode(' ', $matches[1]));
        $new_attributes[] = 'target';
        $new_attributes[] = 'title';
        $new_attributes[] = 'class';
        $config['settings']['allowed_html'] = preg_replace('/&lt;a ([^&gt;]*)&gt;/', '&lt;a ' . implode(' ', array_unique($new_attributes)) . '&gt;', $allowed_html);
        $filter-&gt;setFilterConfig('filter_html', $config);
        $filter-&gt;save();
      }
    }
  }


Don't forget to include:
use Drupal\filter\Entity\FilterFormat;

This code is needed to be run only once, so i had to include it in a .install file in a custom module.