Note that I am using the latest dev branch because it resolved the following issue:
https://www.drupal.org/node/2364559
https://www.drupal.org/node/2177893

What I am doing:

  1. Hit enter several times until you reach the bottom of the body textarea.
  2. Put in a file (I used a PDF) where the textarea ends and starts to expand.
  3. Hit enter again for a new line and this time put in an image.
  4. Switch to plain text editor and notice that the image fid is the same as the file fid from before it.
  5. The image file will now become a duplicate media link of the PDF file before it.

The problem is hard to reproduce, but the above instructions give me the best results. It also happens when I clear the caches on my site, and usually then it happens to two files no matter where I insert them in the body. I have been forced to close the browser window to prevent this from happening. I have tested on Safari, Chrome, and Firefox with the same result. The following is an example of the plain text links as shown on my own site. I simply alternated uploading a PDF file with uploading an image until it broke.

<p>[[{"fid":"536","view_mode":"default","type":"media","link_text":"tutorial-201.pdf","attributes":{"class":"file media-element file-default"}}]]</p>

<p>[[{"fid":"537","view_mode":"default","type":"media","link_text":null,"attributes":{"height":"184","width":"544","class":"media-element file-default"}}]]</p>

<p>[[{"fid":"538","view_mode":"default","type":"media","link_text":"tutorial-201.pdf","attributes":{"class":"file media-element file-default"}}]]</p>

<p>[[{"fid":"539","view_mode":"default","type":"media","link_text":null,"attributes":{"height":"184","width":"544","class":"media-element file-default"}}]]</p>

<p>[[{"fid":"540","view_mode":"default","type":"media","link_text":"tutorial-201.pdf","attributes":{"class":"file media-element file-default"}}]]</p>

<p>[[{"fid":"540","view_mode":"default","type":"media","link_text":null,"attributes":{"class":"file media-element file-default"}}]]</p>

<p>[[{"fid":"540","view_mode":"default","type":"media","link_text":"tutorial-201.pdf","attributes":{"class":"file media-element file-default"}}]]</span></p>

<p>[[{"fid":"540","view_mode":"default","type":"media","link_text":null,"attributes":{"class":"file media-element file-default"}}]]</span></p>

I have poked around a fair amount in the code, but the intermittent nature of this problem (above it took me 5 uploads, other times just 2) and the fact that clearing caches, closing browser windows, and even using different browsers all seem to have some unpredictable results, and I am really stumped on this one.

But, given that many people will attempt to insert two or more files further down in the body of a document, this could be a potentially major flaw in Media CKEditor if it is not resolved. I will keep coming back to it as my time allows, thank you.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rich_dawson created an issue. See original summary.

rich_dawson’s picture

Issue summary: View changes
rich_dawson’s picture

Issue summary: View changes
rich_dawson’s picture

Issue summary: View changes
rich_dawson’s picture

Issue summary: View changes
seanB’s picture

This is probably related to https://www.drupal.org/node/2028231.
There is a patch in #5 that is supposed to work.

the problem was also reported in this issue: https://www.drupal.org/node/2064419

Basically the problem is that the cursor will sometimes end up inside the part of the media tag. When you add another file (or press enter to add another bullit or something), you are still inside the tag of the previous element.

Since the wysiwyg-media.js file is not used when using the ckeditor module, the suggested solution should probably be added somewhere in media_ckeditor as well.

seanB’s picture

I've ported the patch from https://www.drupal.org/node/2028231. This works with the latest dev from the media module. Please review!

Status: Needs review » Needs work

The last submitted patch, 7: media_ckeditor-multiple_media_links_break-2591069-7.patch, failed testing.

Robert_W’s picture

The patch works! The main issue is fixed (which should really be marked as critical in my opinion), but after the patch an additional &nbsp; is inserted. This is related to the patch because when I reverse the patch the additional &nbsp; is gone.

seanB’s picture

I don't have this issue? Where exactly is the &nbsp; inserted? Can you post the HTML output?
What configuration do you have for your media display? Could you also post versions of the media, ckeditor and file_entity modules?

Robert_W’s picture

The patch doesn't seems to work anymore with Media beta2 or the latest dev. After aplying the patch the problem is still there. The first two inserts are fine, but a third (and further) get the same fid as the second file.

Robert_W’s picture

Priority: Major » Critical

Still having issues with multiple media files in a list (ul/li). Media in a list gets the same fid when selecting a middle item in the list and pressing enter. This is becoming critical in my opinion because it makes working with the editor and media difficult. It also breaks when you add some files, select them aferwards and make them list items.

LauraRocks’s picture

Ok, so we stumbled across this as well. We have a customer with a lot of editors and they use a lot of files in the editor fields. And almost every time they try to add multiple documents just by adding file, pressing enter and adding another one, the files get inserted inside one another, and suddenly the markup breaks or the files get the same file id. I did a fresh install with the make file here: https://www.drupal.org/node/2843391 and was able to reproduce the situation. It comes even more clear if you add a file at the end, save, and then come back to edit the node and want to add a file to the end, after the other file. You won't be able to get out of the and tags, or at least the tag.

So, we tried the patch from #7, but couldn't get it to work. And then we realized, that we probably don't want to check the selection every time something changes, but only when the "Add media" button is pressed. So we made another patch trying to solve this case, using the patch in #7 as a reference. I am not sure if the code is very optimal or even the placement of the code, but you get the idea from it. Any thoughts?

joseph.olstad’s picture

Status: Needs work » Needs review

would be nice to have a simpletest for this, but in the absence of one, a human review is fine.

  • LauraRocks authored 4dba240 on 7.x-2.x
    Issue #2591069 by seanB, LauraRocks: Multiple media links break
    
joseph.olstad’s picture

Status: Needs review » Fixed

fixed in media_ckeditor 7.x-2.x dev

joseph.olstad’s picture

Thanks @LauraRocks and @SeanB

Status: Fixed » Closed (fixed)

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