Problem/Motivation
FilterCaption was introduced in #2014895: Image captions & alignment (for inline images) and was slightly improved in #2170085: Caption filter may not wrap images that are only aligned, not captioned.
There is still one remaining problem: the fact that you can only enable alignment (data-align) and captioning (data-caption) at the same time. There is no good reason for them to be together in one filter, other than that being slightly simpler to implement originally.
It also helps in promoting the spirit behind filters: combining many very focused Lego blocks together to a greater whole.
Proposed resolution
We should not force this on people; we should give them the choice. So let's split it up into two separate filters. The consequences are:
filter_align, if used together withfilter_caption, must run firstfilter_captionwill no longer pass aalignparameter to the Twig template, but instead it will pass the value of the captioned element'sclassattribute
Remaining tasks
- We will also need to make sure that the corresponding CKEditor plugins (
drupalimage/drupalimagecaption) can cope with this change, but that should wait on #2039163: Update CKEditor library to 4.4, which is changing them drastically. UpdateFilterUnitTest
User interface changes
Two visible filters instead of one.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | filter_caption_filter_align-2239413-15.patch | 31.98 KB | wim leers |
Comments
Comment #1
wim leersThis patch already works just fine, we just need to wait for #2039163: Update CKEditor library to 4.4 to push it to the finish line :)
Thanks to Piotrek Koszuliński from the CKEditor team for pointing out that this doesn't make sense!
Comment #2
dave reidYes! This makes way more sense, especially for allowing alignment to be used on things that captions don't make as much sense.
Comment #3
dave reidI think this also may require a change to EditorImageDialog to ensure that neither, one of, or both of the 'Alignment' or 'Caption' elements are visible if we're splitting the filters?
Un-postponing since #2039163: Update CKEditor library to 4.4 has been resolved.
Comment #4
wim leersI was waiting for #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags to land as well. That has now landed, so rerolling.
Updated test coverage, and also implemented #3 — which I failed to mention in the issue summary, but of course agree with :)
Comment #6
wim leersFilterAlign.phpwas missing from #4 :/ Stupid!Comment #7
wim leers#6 still applies. Please review!
Comment #8
cs_shadow commentedChanges look good. Just a minor nitpick:
Is assigning NULL to classes necessary here?
Otherwise works like a charm, tested on my dev site.
My only concern is that can we also split the ckeditor/js/plugins/drupalimagecaption/plugin.js similar to the filters as a follow-up?
Comment #9
blueminds commentedReroll.
Re assigning NULL to the classes - not sure if you can do anything else here? You need to have the classes key around, however do not have any value to assign to it at that stage.
If the reroll is okay, for me RTBC.
Comment #10
wim leersGood point! This is also listed in the IS as a remaining task (the last one in fact!).
The existing patch already updates
DrupalImageCaptionandEditorImageDialog, but the JS is indeed not yet updated accordingly. Fixing that now.Comment #11
wim leersRE: assigning NULL to classes: this is the convention, so there's nothing to do there.
I've now updated
ckeditor/js/plugins/drupalimagecaption/plugin.js. The server side tells it which filters are enabled (the alignment or captioning) and it disables corresponding logic accordingly. (I talked to the CKEditor developers what the best approach would be, and they recommended this.)When testing with an image that has both a caption and alignment, and then either disabling the caption or alignment filter and revisiting the node form, you can see that everything is rendered as expected. And when you open the "source" mode, you can see that the data- attribute for the disabled filter is kept. So I can't find any bugs anymore. I can't RTBC my own patch of course.
So if either of you can do another round of manual testing, and you find no problems, you can RTBC this :)
While working on this, I found one bug (which already was present in the above patches): some CSS was not being loaded when the caption filter was disabled, but the alignment filter was enabled.
Comment #12
cs_shadow commentedHappy to mark this as RTBC. Applies cleanly and works perfectly.
Comment #13
slashrsm commented+1 for RTBC.
Comment #14
alexpottMissing the data-align attribute - also given this is user facing text perhaps we shouldn't use llamas here?
I can not see any code that enforces this.
Comment #15
wim leersYou're right, thanks! In fixing that, I also noticed a (pre-existing) typo and incomplete information for the caption filter help text.
That's fair :D
The same "filter X must run before filter Y" exists for almost all filters:
filter_htmlmust run beforefilter_htmlcorrector,filter_html_escapemust run beforefilter_autop, and so on. This is an unsolved problem that we've had for as long the filter system has existed.Comment #16
cs_shadow commentedLGTM.
Comment #17
alexpottCommitted 008fb11 and pushed to 8.0.x. Thanks!
Comment #20
gábor hojtsy