Comments

othermachines created an issue. See original summary.

othermachines’s picture

Status: Active » Needs review
StatusFileSize
new3.3 KB

Here's a patch.

joseph.olstad’s picture

ok , 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 .

joseph.olstad’s picture

hmm 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

joseph.olstad’s picture

@othermachines, what version of the ckeditor library are you using?

othermachines’s picture

Hi, 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

joseph.olstad’s picture

@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?

joseph.olstad’s picture

Also, do you recall details about what the "specific issue" with the latest ckeditor library was?

othermachines’s picture

@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):

"Image properties" in right context menu not present on newly added images. It still exists and is functional on images that have been previously added. There is no discernible difference in "Source" mode (images are tokenized), and toggling source activates the menu item on the new image.

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:

The requested page "/media/undefined/format-form?render=media-popup&fields=undefined" could not be found.

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.

othermachines’s picture

A 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:

config.format_tags = 'p;h2;h3;h4;h5;h6;div';
config.bodyClass = 'ckeditor-textarea';
config.autoParagraph = true;
config.forcePasteAsPlainText = true;
config.justifyClasses = [ 'text-left', 'text-center', 'text-right'];
config.extraPlugins = '';
config.removePlugins = 'image';

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.

[CKEDITOR] Error code: editor-plugin-conflict. {plugin: "image", replacedWith: "image2"}
[CKEDITOR] For more information about this error go to https://ckeditor.com/docs/ckeditor4/latest/guide/dev_errors.html#editor-...

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

joseph.olstad’s picture

have a look at your patch...

Drupal.settings.ckeditor.plugins['media'].compareVersions(CKEDITOR.version, '4.3') >= 0

this 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?

joseph.olstad’s picture

othermachines’s picture

Huh?

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.

joseph.olstad’s picture

ah 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.

joseph.olstad’s picture

Hi @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.6.2 works with image properties with or without the patch
image properties work with 4.6.2 ckeditor with or without patch it works

ckeditor 4.11.4 does not behave as expected (not related to your patch though, with or without the patch)

ckeditor 4.11.4 in my environment does not provide image properties 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?

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

ok I've reviewed this patch, it's good, it's going in!

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

fixed, pushed tag, tagging release shortly!

Thanks for your patch @othermachines, great work!
appreciated.
I will update the media recipe as well.

othermachines’s picture

Regarding #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...

Are you able to get image properties with 4.11.4 ?

Yes, but only by disabling widget support as described in #9.

Glad you found a use for the patch. :)

joseph.olstad’s picture

are 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

othermachines’s picture

Thanks, 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 onLoad altogether. The end result is the same.

Actually, you might as well remove the onLoad as well as any code that follows that requires hasWidgetSupport to evaluate to true, since without that one line it will never run.

joseph.olstad’s picture

ok 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 ?

joseph.olstad’s picture

Hi 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).

othermachines’s picture

@joseph.olstad

does this mean it falls back to legacy token ?

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 requires hasWidgetSupport to be true will never be run because it will never be true.

So this bit will never be run:

      // Ensure the tokens are replaced by placeholders while editing.
      // Check for widget support.
      if (mediaPluginDefinition.hasWidgetSupport) {
        editor.widgets.add( 'mediabox',
        {
          button: 'Create a mediabox',
          editables: {},
          allowedContent: '*',
          upcast: function( element ) {
            // Ensure media tokens are converted to media placeholders.
            html = Drupal.media.filter.replaceTokenWithPlaceholder(element.getHtml());
            // Only replace html if it's different
            if (html != element.getHtml()) {
              element.setHtml(html);
              // CKEditor's setHtml() method automatically fixes the HTML that
              // it receives, which means that if it gets an <li> without a
              // <ul> or <ol> parent, it adds a <ul>. These extra <ul> tags just
              // keep piling up every time this function runs. So check here to
              // see if we may need to fix this.
              if (element.children && element.children[0]) {
                // We identify this by looking for a <ul> inside a <ul> or <ol>.
                if (('ul' === element.name && 'ul' === element.children[0].name) ||
                    ('ol' === element.name && 'ul' === element.children[0].name)) {
                  // If this did happen, fix it by promoting the grandchildren
                  // (ie, actual list items) to children.
                  element.children = element.children[0].children;
                }
              }
            }
            return element.name == 'mediawrapper' || 'data-media-element' in element.attributes;
          },

          downcast: function( widgetElement ) {
            var token = Drupal.media.filter.replacePlaceholderWithToken(widgetElement.getOuterHtml());
            if (token) {
              return new CKEDITOR.htmlParser.text(token);
            }
            return false;
          },

          init: function() {
            // Add double-click functionality to the widget.
            this.on('doubleclick', function(evt) {
              editor.execCommand('media');
            }, null, null, 5 );
          }
        });
      }
      // ...

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.