Last active
December 4, 2018 20:27
-
-
Save laradevitt/8bd8b159db737e9274af3f0505172da4 to your computer and use it in GitHub Desktop.
(Drupal 8.x) Load theme CSS into CKEditor for certain formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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