A frustrating thing for webmasters is often that they cannot see the eventual lay-out of text styling in their CKEditor. This snippet fixes this issue.
Open your mytheme.info.yml and add the line above libraries
or below base_theme
.
....
base theme: stable
ckeditor_stylesheets:
- css/style.css
libraries:
- mytheme/bootstrap
screenshot: screenshot.png
...
/**
* Implements hook_ckeditor_css_alter().
*
* Injects our CSS sheets anytime CKEditor has loaded.
*
* @param array $css
* @param Drupal\editor\Entity\Editor $editor
*/
function MYMODULE_ckeditor_css_alter(array &$css, Editor $editor) {
if (!$editor->hasAssociatedFilterFormat()) {
return;
}
$known_formats = [
'basic_html',
'full_html',
];
if (in_array($editor->getFilterFormat()->id(), $known_formats)) {
$css[] = drupal_get_path('theme', 'MYTHEME') . '/css/main.css';
}
}