Skip to content

Instantly share code, notes, and snippets.

@laradevitt
Last active December 4, 2018 20:27
Show Gist options
  • Save laradevitt/8bd8b159db737e9274af3f0505172da4 to your computer and use it in GitHub Desktop.
Save laradevitt/8bd8b159db737e9274af3f0505172da4 to your computer and use it in GitHub Desktop.
(Drupal 8.x) Load theme CSS into CKEditor for certain formats
<?php
use Drupal\editor\Entity\Editor;
/**
* Implements hook_ckeditor_css_alter().
*
* Original source: https://drupal.stackexchange.com/a/225532
*/
function mytheme_ckeditor_css_alter(array &$css, Editor $editor) {
// Load front end theme CSS into CKEditor for certain formats.
if (!$editor->hasAssociatedFilterFormat()) {
return;
}
$known_formats = [
'basic_html',
'full_html'
];
if (in_array($editor->getFilterFormat()->id(), $known_formats)) {
// Add main theme stylesheet.
$css[] = drupal_get_path('theme', 'mytheme') . '/css/app.css';
// Add extra CSS for CKEditor.
$css[] = drupal_get_path('theme', 'mytheme') . '/css/ckeditor.css';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment