Change record status: 
Project: 
Introduced in branch: 
8.1.x
Description: 

Loading additional CSS in CKEditor iframe instances no longer requires hook_ckeditor_css_alter() to be implemented, along with logic to determine whether the plugin is enabled.

Remember, a CKEditor plugin can be enabled based on a button being added (\Drupal\ckeditor\CKEditorPluginButtonsInterface) or based on the context, whether that is a setting, a filter, another plugin being enabled, et cetera (\Drupal\ckeditor\CKEditorPluginContextualInterface). So the logic to match that in hook_ckeditor_css_alter() could easily become very complex, or — more often — a rough approximation, which meant the CSS was actually being loaded in cases where it wasn't necessary.

Now, instead the \Drupal\ckeditor\CKEditorPluginInterface\CKEditorPluginCssInterface can be implemented by the Drupal plugin that makes a CKEditor plugin available.

Before

function mymodule_ckeditor_css_alter(array &$css, Editor $editor) {
  // Add CSS based on text filter being enabled.
  if ($editor->getFilterFormat()->filters('filter_caption')->status) {
    $css[] = drupal_get_path('module', 'mymodule') . '/css/filter.css';
  }

  // Or add CSS based on plugin being enabled: if the button is present and/or when it's enabled based on context.
  if ($editor->getSettings()->…[TRICKY CODE HERE]) {
    $css[] = drupal_get_path('module', 'mymodule') . '/css/my-ckeditor-plugin.css';
  }
}

After:

function mymodule_ckeditor_css_alter(array &$css, Editor $editor) {
  // Add CSS based on text filter being enabled.
  if ($editor->getFilterFormat()->filters('filter_caption')->status) {
    $css[] = drupal_get_path('module', 'mymodule') . '/css/filter.css';
  }
}

modules/mymodule/src/Plugin/CKEditorPlugin/MyPlugin.php

public function getCssFiles(Editor $editor) {
  return array(
    drupal_get_path('module', 'mymodule') . '/css/my-ckeditor-plugin.css'
  );
}
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done