Using media and the CKeditor modules, when I add an image in a table cell it initially appears to be in the correct place but when I save (or click the link to disable CKeditor and see the markup) the image ends up above the table in a p tag.

When the image is initially inserted the markup looks like this:

<table cellspacing="1" cellpadding="1" border="1" summary="test">
  <caption>test</caption>
  <tbody>
    <tr>
      <td>asdfasd</td>
      <td>asdfasdf</td>
      <td>asdfasdf</td>
    </tr>
    <tr>
      <td>asdfasdfas</td>
      <td>
        <mediawrapper data="">
          <img width="253" height="138" title="sdfgsdf" alt="sdfgsdfg" src="http://example.com/sites/default/files/styles/stylename/public/image.jpg?itok=y3pCSk2k" data-fid="544" data-media-element="1" class="media-element file-wysiwyg" _moz_resizing="true">
        </mediawrapper>
        <br>
      </td>
      <td>asdfasdfasd</td>
    </tr>
  </tbody>
</table>

After it looks like this:

<p>&nbsp;</p>
[[{"fid":"544","view_mode":"wysiwyg","type":"media","attributes":{"alt":"sdfgsdfg","title":"sdfgsdf","height":138,"width":253,"class":"media-element file-wysiwyg"},"link_text":null}]]

<table border="1" cellpadding="1" cellspacing="1" summary="test">
  ...
</table>

Then after another save it looks like this

<p>&nbsp;</p>

<p>[[{"fid":"544","view_mode":"wysiwyg","type":"media","link_text":null,"attributes":{"alt":"sdfgsdfg","title":"sdfgsdf","height":138,"width":253,"class":"media-element file-wysiwyg"}}]]</p>

<p>&nbsp;</p>

<table border="1" cellpadding="1" cellspacing="1" summary="test">
  ...
</table>

It seems that if I then edit the node, switch to non-wysiwyg mode and manually move the media token back into the table, like this, then it works again:

<table cellspacing="1" cellpadding="1" border="1" summary="test">
  <caption>test</caption>
  <tbody>
    <tr>
      <td>asdfasd</td>
      <td>asdfasdf</td>
      <td>asdfasdf</td>
    </tr>
    <tr>
      <td>asdfasdfas</td>
      <td>[[{"fid":"544","view_mode":"wysiwyg","type":"media","link_text":null,"attributes":{"alt":"sdfgsdfg","title":"sdfgsdf","height":138,"width":253,"class":"media-element file-wysiwyg"}}]]</td>
      <td>asdfasdfasd</td>
    </tr>
  </tbody>
</table>

Then when I go back to the wysiwyg mode the markup is now this:

<table cellspacing="1" cellpadding="1" border="1" summary="test">
  <caption>test</caption>
  <tbody>
    <tr>
      <td>asdfasd</td>
      <td>asdfasdf</td>
      <td>asdfasdf</td>
    </tr>
    <tr>
      <td>asdfasdfas</td>
      <td><img width="253" height="138" src="http://example.com/sites/default/files/styles/stylename/public/image.jpg?itok=y3pCSk2k" data-cke-saved-src="http://example.com/sites/default/files/styles/stylename/public/image.jpg?itok=y3pCSk2k" data-media-element="1" data-fid="544" class="media-element file-wysiwyg" alt="sdfgsdfg" title="sdfgsdf"></td>
      <td>asdfasdfasd</td>
    </tr>
  </tbody>
</table>

So the difference between that and the broken one is the mediawrapper tag and the data-cke-saved-src attribute.

Comments

rooby’s picture

Issue summary: View changes
rooby’s picture

Issue summary: View changes
rooby’s picture

Issue summary: View changes
seanpclark’s picture

The ckeditor code is currently being decoupled from media (https://www.drupal.org/node/2532974), so I added a patch specific to my project to remove the mediawrapper tag on insert from the library.js file (modules/media_wysiwyg/wysiwyg_plugins/media_ckeditor/library.js). I'm not clear if mediawrapper is still needed for some scenario I haven't run into, but it appears to introduce problems when the image is translated back and forth to a token.

g33kg1rl’s picture

What would be the best solution if I want to use the media module with the ckeditor without running into this issue?

Chris Matthews’s picture

Status: Active » Closed (outdated)

Recent versions of media have resolved most of peoples concerns and is compatible with entity translation, multilingual and various advanced configurations. Due to the high volume of inactive and most often irrelevant issues we are Closing this as (outdated). If for whatever reason this issue is important to you AND you still have issues after checking the media recipe documentation, then let us know and we will review your concerns.

Otherwise, see the recipe documentation for how to configure media and for troubleshooting tips OR refer to the media_dev distribution if you want to see a working media setup.

As mentioned, feel free to make some noise in this issue if you still feel it is important to you or someone else.

Thanks,

Media team