Hello!
A buggy version check was recently fixed in js/plugins/media/library.js. The fix needs to be implemented in js/plugins/media/plugin.js as well.
Related:
(Commit) Issue #3007950 by ron_s: Improper version checking causes CKEditor 4.10.1 to break inserting images
(Issue comment) #3007950-17: Improper version checking causes CKEditor 4.10.1 to break inserting images
Patch to follow.
Comments
Comment #2
othermachines commentedHere's a patch.
Comment #3
joseph.olstadok , I'm tempted to put this in right away, do you have a quick test scenario of before and after?
or just exactly what ron_s says in other issue .
Comment #4
joseph.olstadhmm othermachines.. the logic here:
Drupal.settings.ckeditor.plugins['media'].compareVersions(CKEDITOR.version, '4.1') >= 0
>=0 means false or true would pass here as this is truthy
Comment #5
joseph.olstad@othermachines, what version of the ckeditor library are you using?
Comment #6
othermachines commentedHi, Joseph. I assumed the version checking was sound. My patch just expands on where it is being used.
I did have a specific issue after updating to latest CKEditor but it was fixed by #3007950: Improper version checking causes CKEditor 4.10.1 to break inserting images so isn't relevant to this patch.
Thanks!
*Edit: fixed issue link
Comment #7
joseph.olstad@othermachines, I have another question, recently I noticed problems with ckeditor library version 4.10.1 with regards to integration with the ckeditor image dialog for resizing and right click image option in embedded images when used in conjunction with media_wysiwyg and media_ckeditor on embedded images inserted in body text.
reverting to 4.6.2 solved this problem for us.
I did a bit of digging it seems some others were having issues as well, are you saying that this patch resolves this type of thing for 4.10.1 ? Is your image dialog working as you would expect for changing class and image width and image height ? I updated the media recipe recently to specify 4.6.2 of the ckeditor library for this reason. So now I am recommending 4.6.2
however just curious if things are working well for you with 4.10.1? if so could I have a look at your demo site maybe or could you provide a screenshot or two please?
Comment #8
joseph.olstadAlso, do you recall details about what the "specific issue" with the latest ckeditor library was?
Comment #9
othermachines commented@joseph.olstad - Sure, happy to provide more details if it helps.
When I updated our sites to CKEditor 4.11.4 from 4.9.2 (from our internal issue queue):
This was happening because 4.11.4 wasn't passing the version check fixed in #3007950: Improper version checking causes CKEditor 4.10.1 to break inserting images.
That being said, as part of our own "recipe" to get things working (at least to 90%) we've had to disable the widget functionality. We do that by removing the 'OnLoad' property in plugin.js which forces it to fall back to old token handling. (It looks like you've recently had a similar revelation over here?: #2813413-35: Unable to resize images inserted with Media). This resolves issues for us regarding accessing the "Image properties" options.
This doesn't fix everything, however. When a caption is added (by checking "caption" in Image properties) and the node is saved, when the node is subsequently edited we lose access to the media browser (in the image context) and instead get an error in the modal:
Anyway, despite the issues we've managed to keep 30+ schools reasonably happy for several years, so that's not bad. :)
Let me know if you need any more info.
Comment #10
othermachines commentedA bit more info:
Forgot to mention that another issue with captioned images is that they can't be resized (either by dragging or via "Image properties"). Non-captioned images are fine.
CKEditor profile settings:
Selected plugins:
[x] Plugin for inserting Drupal teaser and page breaks.
[x] Enhanced Image plugin. See addon page for more details.
[x] Plugin for embedding files using Media CKEditor
[x] Plugin for embedding HTML snippets
[x] Table Resize plugin. See addon page for more details.
ACF: Disabled
Custom Javascript configuration:
I added
config.removePlugins = 'image';since the update to 4.11.4 to deal with warnings in the console (below) and it doesn't seem to make a difference otherwise.Versions:
- drupal 7.67
- media_ckeditor (latest dev)
- media 7.x-2.19
- ckeditor 7.x-1.18
- file_entity 7.x-2.21
Cheers -
**Edit - added project versions
Comment #11
joseph.olstadhave a look at your patch...
Drupal.settings.ckeditor.plugins['media'].compareVersions(CKEDITOR.version, '4.3') >= 0this code seems to me like it will ALWAYS resolve to TRUE.
because if compareVersions returns false, false is = 0 and therefore == 0 resolves to true
and if compareVersions is true or an integer it will resolve to true.
So this logic seems flawed in the fact that your code seems to not care at all what version it is, even if it's version 2 it will resolve to false and pass the condition.
?
If you could do me a favour, try CKEDITOR version 4.2 , I bet this condition will resolve to true, put a console.log inside that statement, remove the second condition and it will output something.
however that doesn't mean that CKEDITOR version 4.2 will work properly it just means that the version compare will pass the condition.
so while I appreciate very much your work on this issue, the patch smells fishy, while it might work just because your ckeditor is obviously higher than 4.2
but the intention was to make sure it is higher than 4.2 and I don't think the logic is doing that now.
With that said, how many people are using 4.2 ? or lower? not sure, probably still lots, so if I put this patch in, unexpected results for people with ckeditor library 4.2 , I'm not even sure what it'd do.
Is this version check really necessary anymore ? maybe we just remove it and put in the release notes that you HAVE to have CKEDITOR 4.3 or higher, because this logic maybe isn't even necessary.
What is your opinion?
make sense?
Comment #12
joseph.olstadexplanation here:
Comment #13
othermachines commentedHuh?
Again, I did not introduce the version checking in this patch. It was introduced by yourself and @ron_s in this issue: #3007950: Improper version checking causes CKEditor 4.10.1 to break inserting images
Maybe you will find some answers to your concerns here, as it looks to be where this technique originated. It also has tests: https://stackoverflow.com/a/16187766/4483099
If implementing calls to a version check that *you* committed for the sake of being thorough "smells fishy", then I can't be of any assistance here. I honestly don't care if you use it or not.
Comment #14
joseph.olstadah sorry yes you're correct, I had a look at that function, it returns positive numbers, 0 and negative numbers, the return value description helped clear that for me.
Ok thanks for this patch I think it's good we should put it in asap, good detective work!
I would like to test it out myself first though, I have an environment to test with so should be easy.
Comment #15
joseph.olstadHi @othermachines, good news, your patch does not cause a regression. However please review my screenshots, something else in my test environment maybe is preventing image properties dialog from working with the right click when switching from ckeditor 4.6.2 to 4.11.4.
I really appreciate your input here, so I did test your patch, it didn't cause a regression for me. However can you please look at my screenshots and provide feedback to tell me if your environment is working as I would expect?
I tested the patch with ckeditor 4.6.2 and 4.11.4 with or without it was the same behavior for me. No javascript console errors but no image properties in 4.11.4.
For whatever reason my environment degrades with 4.11.4 so I reverted to 4.6.2
Are you able to get image properties with 4.11.4 ?
Please see my screenshots below
ckeditor 4.6.2 behaves as expected, see screenshot (with or without your patch it works fine)
ckeditor 4.11.4 does not behave as expected (not related to your patch though, with or without the patch)
NOTE: this might just be something with my test environment, I will try to test with the media_dev distribution which is more of a baseline setup than the above illustrated test environment. With that said, I'd like to hear from your feedback, if these screenshots tell you anything?
Comment #16
joseph.olstadok I've reviewed this patch, it's good, it's going in!
Comment #18
joseph.olstadfixed, pushed tag, tagging release shortly!
Thanks for your patch @othermachines, great work!
appreciated.
I will update the media recipe as well.
Comment #19
othermachines commentedRegarding #15 - Unless I fall back to the old token handling (as I described in #9) I don't get "Image properties" in the menu in either 4.9.x or 4.11.x. I can't easily roll back to 4.6.2 as I get unrelated JS errors that I don't have time to look into, sorry.
This applies to newly added images only, not images that are already embedded and saved.
So what you describe in #15 does not surprise me at all.
To answer your question...
Yes, but only by disabling widget support as described in #9.
Glad you found a use for the patch. :)
Comment #20
joseph.olstadare you using the lineutils , widget and widgetselection plugins? if not, consider adding those , make sure they match the version of your ckeditor library (4.11.4)
the download links to those plugins are in the media recipe page
Comment #21
othermachines commentedThanks, yes I do but I'm not having issues. I was just giving you feedback on #15.
I just noticed that the patch you just committed (49fbf58d) does the exact same thing as what I described in #9. It disables widget support, which means it falls back to old token handling. Our own patch removes the
onLoadaltogether. The end result is the same.Actually, you might as well remove the
onLoadas well as any code that follows that requireshasWidgetSupportto evaluate to true, since without that one line it will never run.Comment #22
joseph.olstadok thanks for those notes,
another clarification "falls back to old token handling"
does this mean it falls back to legacy token ?
like here:
/admin/config/media/browser
Option) Full file entity rendering
Option) Legacy rendering (using field attach)
during my tests I was using the option 'Legacy rendering (using field attach)
Is this the 'falls back to old token handling' that you're referring to ?
Comment #23
joseph.olstadHi Othermachines yes this is a good idea, if you push a patch for the removal of the onload code as mentioned I will review it and probably push it in (no sense leaving code in there that will never get executed).
Comment #24
othermachines commented@joseph.olstad
I don't think so, but I don't know enough about how the media module works to know for sure. (Ours have always been set to "Full file entity rendering".)
What I meant is, in
mediaPluginDefinition.init()(plugin.js), any code that requireshasWidgetSupportto be true will never be run because it will never be true.So this bit will never be run:
I wonder if it's worth looking at whether it can be fixed before removing it altogether? I honestly have no idea. Beyond occasionally tweaking to make things work I'm not experienced with CKEditor plugins.