Problem/Motivation
Bartik uses ckeditor-iframe.css to load CKEditor styles when Bartik is the admin theme, but it only includes the styles for the caption.
Instead we could load Bartik's frontend CSS stylesheets in the CKEditor. This would be simpler and easier to maintain as it is loading stylesheets for the frontend and we will not have two sets of styles to upkeep.
Proposed resolution
Remove ckeditor-iframe.css and replace with applicable Bartik CSS stylesheets.
Remaining tasks
Wait until #2375673: Split Bartik's CSS into SMACSS style components is committed.
Un-postpone this issue.
Write a patch replacing the loaded CSS files in bartik.info.yml.
Test patch in CKEditor in Bartik.
Add test screenshots.
Review patch.
Add review screenshots.
User interface changes
API changes
Original report by @Wim Leers
Reported by Dharmesh Mistry.
Bartik should ship with a CKEditor stylesheet, so that sites using Bartik (all default Drupal 8 installations) have as close a match as possible between what is seen in CKEditor on the node add/edit form and what is seen on the front-end.
In bartik.info.yml
:
ckeditor_stylesheets:
- css/ckeditor-iframe.css
Beta phase evaluation
Issue category | Task as CKEditor functions fine as it is but it lacks styles to show how elements are represented on the frontend. |
---|---|
Unfrozen changes | Unfrozen because it only changes which CSS files are used to show visual styles in CKEditor |
Comment | File | Size | Author |
---|---|---|---|
#28 | 2064379-27-frontend.png | 1.35 MB | bneil |
#28 | 2064379-27-WYSIWYG-before.png | 1.21 MB | bneil |
#28 | 2064379-27-WYSIWYG-after1.png | 1.19 MB | bneil |
#28 | 2064379-27-WYSIWYG-after2.png | 1.16 MB | bneil |
#24 | interdiff-18-23.txt | 1.17 KB | tadityar |
Comments
Comment #1
Wim Leers#2027181: Use a CKEditor Widget to create a stellar UX for captioning and aligning images added
core/themes/bartik/css/ckeditor-iframe.css
, but it only includes the styles for the caption.I just thought of something: is there any reason why we couldn't just load Bartik's entire
style.css
? That'd be heavily overkill, but it'd also be simpler, and easier to maintain.Comment #1.0
Wim LeersUpdated issue summary.
Comment #2
emma.mariaWe are currently in the process of splitting styles.css up into SMACCS style stylesheets #2375673: Split Bartik's CSS into SMACSS style components.
Once this change has been committed I agree with @Wim Leers that we should load Bartik frontend CSS files and take out ckeditor-iframe.css.
We will be able to pick and choose which CSS files we need as everything will be split into components and having one version of the CSS for frontend and the Bartik CKEditor backend will be easier to maintain.
We also will not need ckeditor-iframe.css as captions.css file has been created as part of #2375673: Split Bartik's CSS into SMACSS style components and we can load that with the other relevant files.
Currently postponing the issue as we are working hard on #2375673: Split Bartik's CSS into SMACSS style components and any work done on this now will not be a good use of time.
I also have updated the issue summary to represent better what we hope to achieve.
Comment #3
emma.mariaComment #4
emma.mariaComment #5
Wim LeersAgreed — and awesome! :) Can't wait to review a patch :)
Comment #6
emma.mariaAnd I officially declare this issue active again now that #2375673: Split Bartik's CSS into SMACSS style components has been committed :)
Comment #7
emma.mariaComment #8
emma.mariaComment #9
tadityar CreditAttribution: tadityar commentedComment #10
tadityar CreditAttribution: tadityar commentedforgot to add the deleted file.. sorry
Comment #12
tadityar CreditAttribution: tadityar commentedComment #13
tadityar CreditAttribution: tadityar commentedSeems like one more file needed to be changed.
Comment #15
emma.mariaGood start, but we need to add more than just captions.css, as suggested in #1 and then adapted for the new Bartik file structure in #2.
Include as many files as you can see that provide Bartik styles to elements that a user could include in the ckeditor. So basic element styling for text, tables etc etc.
Comment #16
tadityar CreditAttribution: tadityar commentedstill not sure what's more to add..
Comment #18
tadityar CreditAttribution: tadityar commentedupdating the test to see if every stylesheets needs to be included there
Comment #19
Wim LeersLooking good!
buttons.css is unnecessary IMHO; content should never contain buttons.
Might as well have been called
node.css
, because it contains node-related styling.Irrelevant inside CKEditor.Actually, if there's an entity reference that we render inside CKEditor (in a CKEditor Widget), then this *would* be useful! But if we have this, then we'll also wantuser.css
.Comment #20
emma.maria@Wim Leers Agree with renaming content.css to node.css. We have this issue #2398463: Clean up the "content" component in Bartik for cleaning up content.css and it was suggested to change the file name to node.css also over there. We will do that over there with all the CSS/template work for content/node.
So we only need to implement 1. from #19 in this issue.
Comment #21
tadityar CreditAttribution: tadityar commentedThank you for the review! I'll update my patch in #18 when I get home.
Btw, whoever that do this #2398463: Clean up the "content" component in Bartik will replace all occurences of content.css with node.css right? (So I don't have to worry someone might have to re-do this)
Comment #22
Wim LeersIndeed; you don't have to worry about
content.css
. :)Comment #23
tadityar CreditAttribution: tadityar commentedOk, added suggestion from #19.1. I'll leave 19.2 for the other issue :)
Comment #24
tadityar CreditAttribution: tadityar commentedOh my form got outdated.. the real patch now.
Comment #25
bneil CreditAttribution: bneil commentedPatch from comment #24 applies successfully. I manually tested the patch by creating a node and testing out various HTML elements and styles in the WYSIWYG and cross referencing them with viewing the saved node.
Setting to RTBC as I believe the patch satisfies the issue summary and the css it loads is the pertinent css files from Bartik.
Comment #26
Wim LeersRTBC +1, all my remarks from #19 have been addressed.
Comment #27
webchickWould it be possible to get before/after screenshots here, please?
Comment #28
bneil CreditAttribution: bneil commentedHere are screenshots of a basic page of content using the default set of button configuration for the Full HTML text format.
Frontend - Bartik
CKEditor - Before patch
CKEditor - After patch
I had to split this up into two screenshots, due to some of the text spacing changes. CKEditor wouldn't expand long enough for my test content. Too many cat photos?
Summary of changes
The following changes are visibly more consistent with the frontend Bartik theme:
Comment #29
alexpottTheme changes are not blocked by beta. Committed 8b9b0d7 and pushed to 8.0.x. Thanks!
Comment #32
cosmicdreams CreditAttribution: cosmicdreams commentedFinally tracked this issue down to here.
I noticed that after this patch came in the editor lost the nice 8px margin that it once had. But now I fear that we've lost even more.
Can you please explain to me how a developer can control the styles that appear in the text editor in such a way that doesn't break the styles that appear when rendered.
Historically, having styles that work in the text editor AND the markup that it produces have been a terribly difficult thing to master. I had been hopeful that having a designated stylesheet would make it easy for front end developers to place their editor styles into a file and be done with it. Now it sounds like one would need to have knowledge of Drupal's internal handling of styles in order to accomplish the same result.
Can you please point me to a reference implementation of how to do this the right way now? Does the ckeditor_stylesheets directive still work as advertised? Is there are good reason why we're overriding the 8px margin inside the editor?