I have recently updated my site to Media 2.0-unstable7 with Media Colorbox 1.0-rc3.

After updating the modules, I found that colorbox no longer works in WYSIWYG. I have checked the configuration for the 'Colorbox' manage display in the 'Image' file type. However when I used the WYSIWYG to embed an image using the Colorbox view mode, the image is inserted as just a normal image, and does not link to the larger sized image in a lightbox.

This is the code inserted by the Media Browser on WYSIWYG:

<p><a data-file_info="%7B%22fid%22:%228864%22,%22view_mode%22:%22colorbox%22,%22type%22:%22media%22%7D" href="/media_colorbox/8864/media_original/en" title="" class="media-colorbox media-element file-colorbox" rel="" data-mediacolorboxfixedwidth="" data-mediacolorboxfixedheight="" data-mediacolorboxaudioplaylist="0"></a></p><div id="file-8864" class="file file-image file-image-jpeg contextual-links-region"><h2 class="element-invisible">test.jpg</h2><div class="contextual-links-wrapper"><ul class="contextual-links"><li class="file-edit first">Edit</li><li class="file-delete last">Delete</li></ul></div><div class="content"><img typeof="foaf:Image" src="http://test.local/sites/files/test/styles/large/public/field/field_publication_cover/test.jpg" alt="" title="" height="738" width="472" /></div></div><p><a data-file_info="%7B%22fid%22:%228864%22,%22view_mode%22:%22colorbox%22,%22type%22:%22media%22%7D" href="/media_colorbox/8864/media_original/en" title="" class="media-colorbox media-element file-colorbox" rel="" data-mediacolorboxfixedwidth="" data-mediacolorboxfixedheight="" data-mediacolorboxaudioplaylist="0"></a></p>

Please let me know if there are more information you need.

Thanks,
Victoria

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kazanir’s picture

Victoria: I have this problem as well, and it might be a Media problem rather than a Media Colorbox problem per se. You can work around it by using devincarlson's Media Wysiwyg View Mode sandbox project, located here: http://drupal.org/sandbox/DevinCarlson/1823634

This module allows you to "tell" the WYSIWYG editor to only display a certain formatter (in my case, Preview) WITHIN the edit box, and actually transition to the selected view mode once the node is saved.

In my case, we do the following:

1. Set up "Teaser" as the "colorboxed" view mode
2. Set up "Preview" as an image thumbnail. This is the first half of the view modes selected in the Colorbox settings for Teaser.
3. Set up "Colorbox" or "Original" as the actual image. This is the second half of the view modes selected in the Colorbox settings for Teaser, which shows up in the colorbox as planned.

The sandbox will make sure that only the "Preview" thumbnail shows up within the edit iframe, which prevents the error you're seeing.

victoriachan’s picture

Thanks, Kazanir. I'll check that out.

victoriachan’s picture

Hi,

I have looked into this, and the module in comment #1 does sort of fixed this indirectly. The media_wysiwyg_view_mode module allows you to set which view mode to display within the WYSIWYG editor when a file is inserted inline. Hence overriding Media Colorbox's faulty markup for the output in the WYSIWYG.

For people considering using the media_wysiwyg_view_mode module to get around this, note also that because you have defined a specific view mode to be used in the WYSIWYG, that means that no matter which image format is selected for the embed, the image displayed within the WYSIYWYG editor will be displayed in the same size. This might confuse site editors. The rendered page, however, will display the correct image format.

I don't think this is a problem with Media. While looking into it, I found that it is a problem with Media Colorbox's output to the WYSIWYG. The correct output should be something like:

[[{"fid":"8909","view_mode":"colorbox","type":"media","attributes":{"height":180,"width":180,"alt":"Test alt","title":"Test title text","class":"media-element file-colorbox"}}]]

While the incorrect one currently inserted by Media Colorbox is:

<a data-file_info="%7B%22fid%22:%228909%22,%22view_mode%22:%22colorbox%22,%22type%22:%22media%22%7D" alt="Test alt" width="180" height="180" href="/media_colorbox/8909/media_original/en" title="Test title text" class="media-element file-colorbox" rel="" data-mediacolorboxfixedwidth="" data-mediacolorboxfixedheight="" data-mediacolorboxaudioplaylist="0"></a></p><div id="file-8909" class="file file-image file-image-jpeg contextual-links-region"><h2 class="element-invisible">Not a bunny</h2><div class="contextual-links-wrapper"><ul class="contextual-links"><li class="file-edit first">Edit</li><li class="file-delete last">Delete</li></ul></div><div class="content"><img typeof="foaf:Image" src="http://test.local:4567/sites/files/test/styles/large/public/media/bunny_not10.jpg" alt="Test alt" title="Test title text" height="540" width="472" /></div></div><p><a data-file_info="%7B%22fid%22:%228909%22,%22view_mode%22:%22colorbox%22,%22type%22:%22media%22%7D" alt="Test alt" width="180" height="180" href="/media_colorbox/8909/media_original/en" title="Test title text" class="media-element file-colorbox" rel="" data-mediacolorboxfixedwidth="" data-mediacolorboxfixedheight="" data-mediacolorboxaudioplaylist="0"> </a>

And in Media's defense, I am also using Media Soundcloud, Media Youtube, and Media Vimeo, and have not had similar problem with those. I think Media Colorbox just has to output the plain image without the colorbox link in the WYSIWYG (it shouldn't have to be clickable within the WYSIWYG editor anyway).

I've been trying to create a fix for this, but didn't have any success. Will look again when I have time. In the meantime, it would be great if someone more familiar with Media could fix this.

Thanks,
Victoria

Kazanir’s picture

Yeah, what I posted is definitely a workaround and I ran into the same sub-issue with image view modes and so on.

haffmans’s picture

Status: Active » Needs review
FileSize
4.11 KB

Attached is a patch I came up with that seems to solve the problem. It's not yet heavily tested, all I did was check the WYSIWYG stuff. Using media colorbox for images in fields etc. is still untested.

Essentially the patch directly uses the available file as given from the media browser (with $file->override['wysiwyg'] == TRUE) to the theme function. The theme function checks for this override and, if present, simply renders the preview view of the image, rather than outputting a link etc.

The WYSIWYG content that's shown if you disable rich text, is of the [[{'fid': .... }]] form, as expected.

victoriachan’s picture

@haffmans: Sounds great! Thanks for the work. I'll try out your patch and let you know if it works.

georgedamonkey’s picture

I've tested the patch, and it works great! Well, minus one small detail, and maybe I'm just going about this the wrong way. Before, I could insert the image using media, and then double-click the image which would bring up the image properties dialog box. Within here, I could choose 'align left' or 'align right'. Since I applied the patch, It aligns properly in the editor, but when I actually view the page it does not. Is there maybe an error in the patch? Or, is there a different/better way to align images in content with media?

agoradesign’s picture

Great work! I can confirm that the patch works as expected! :)

Nevertheless I want to mention that using Wysiwyg + CKEditor lib + Media Colorbox cost me lot of time to get it to work as expected. Out of the box, the actual output on the page was full of junk like contextual-links (even visible for anonymous guests!), an invisible h2 plus a div-wrapped output, which caused another problem: the invalid markup with the divs inside a link, that itself is sitting inside a paragraph. While I thought, that would be ok - but still ugly - in HTML5, Firefox and Opera (didn't test others) were rendering the <a> element twice - although it was only appearing once in source. Which lead me to the problem that I had duplicate images in the colorbox. To get a better idea, of what I mean, please have a look at the original issue summary above, where you can also see all this extra markup.

The output is coming from the file_entity.tpl.php template because the image is rendered as entity. By removing all the extra markup there, I solved my little problem - additionally one may also override theme_media_colorbox() and use the media_colorbox_strip_only() function to clear both links and divs.

The question now is: is this a bug or a feature? And who's responsiblity is it to get this working out of the box? Should the Media Colorbox module do more and better cleanup or does file_entity provide a bad base template? Hard to say from my perspective, as I avoid using view modes for files for image fields, preferring the image field formatters. The only thing I can see is, that when using "normal" file view modes (=without Media Colorbox) within Wysiwyg + CKE, I never had these problems. So it seems that the Media module is rendering images differently

weseze’s picture

I can confirm that patch from #5 fixed the issue for me.

kaido.toomingas’s picture

My way to work this out was overwrite the formatter by showing just an image for edit and format-form form this added my data without any problems. Why I did something like that? Seems like this problem is bigger than just media colorbox module. If you have colorbox module installed then you can start using colorbox formatter and it will fail becouse this will add data with a link. I really did my own module and learned all this by doing it.
This code under my text is just an example and could maybe help to solve this..

  if (arg(2) != ('edit')&& arg(2) != 'format-form') {
    return l($image, $variables['link']['path'], $options);
  }
  else {
    return $image;
  }

But the real reason http://drupal.org/node/1451316

agoradesign’s picture

Thanks for your input. That looks very promising. I'll give it a try, when I face this problem the next time! :)

martins.bertins’s picture

I fixed the problem with the attached patch.
Instead of rendering the whole file entity I just render the file portion of the entity.

u8915055’s picture

I just wanted to say that #12 worked better in terms of the wysiwyg. I tried out #5, and for some reason it was rendering the 'img' outside of the 'a' '/a' in a separate 'div' and so the preview file display showed up properly in the wysiwyg editor, but in the actual content view, there was nothing to click on as the 'a' for the colorbox trigger was misplaced.

However, using #12 in the content view, the preview file view (large filetype icon) is shown now instead of a thumbnail of the video (understandable).

Let me step back... i have setup things as shown in #1. I have created a thumbnail and added it to the the video file type as an image field.
Now prior to applying the patch, i would get the thumbnail rendered properly in the wysiwyg editor, and properly in the content page where i inserted the video, however as discussed here, there was a whole bunch more markup in the editor.

What i was doing prior to the patch was to just edit the source after inserting the video and manually removing all this extra markup. That worked, but is tedious.

So i applied the patch #12, all that extra markup is gone as expected, however the preview thumb is no longer showing (understandable) and in the content view itself, i just see the large filetype icon and not the thumbnail.

I suppose i could probably fix this by not inserting it through wysiwyg but rather using a view.

Im a bit of a drupal newbie here so im not sure of another way to fix this.. is it possible to change the file_entity template maybe?

Thank you very much for your efforts here.

Tom

haffmans’s picture

You can easily override file_entity.tpl.php in your theme (copy the file to your theme's directory, then remove all the markup from there).

I encountered the same problems with the markup in the final result. I've edited my patch to always simply render the file (similar to #12). The major functional difference with #12 is now that no link is created for the WYSIWYG output, which may solve problems getting the thumbnail to show up in the WYSIWYG editor (I'm not sure).

dalin’s picture

Status: Needs review » Needs work

I think this approach is similar to what's being done elsewhere. A few minor touch-ups needed on the patch though:

if($file!=NULL){

Code style. We need some spaces in there.

+ //'text' => drupal_render($variables['item']),

This is obviously not the way to do this, so lets just pull it out completely.

Lukas von Blarer’s picture

This patch doesn't solve the issue for me. I still have the wrong encoded media placeholder and the colorbox does not work.

lsolesen’s picture

I've applied the patch in #14 and it seems to work. However, it writes the html directly in the field. Shouldn't it use a media placeholder, so I could change the colorbox view mode, and have that applied to everywhere where I used the colorbox view mode to show my image?

Lukas von Blarer’s picture

True. I realized that I am facing the same issue described in #8. Using the instructions in #1 I have a kind of usable solution.

thekevinday’s picture

For those using media 7.x-2.x, there was a similar problem here: #1942688: Documents embedded in WYSIWYG get converted to HTML by the editor.

I suggest applying that fix along with this one or switching to the dev branch of media before trying this patch.

With both patches applied, the media syntax remains the same for me.

RoSk0’s picture

+1 to #14. Works with latest media(2013-Jul-03).

Greg Boggs’s picture

The patch in #14 does not work for me using the latest dev checkout of media 2 and the dev checkout of media colorbox.

I'm not certain what I've done differently that's caused it not to work. Can anyone shed some light on this?

RoSk0’s picture

@Greg Boggs: This might be settings problem. You should enable ONLY "Media Colorbox" display on "admin/structure/file-types/manage/image/file-display/colorbox". One additional thing i noticed, but didn't look for fix, is that you MUST TOTALLY uninstall previous versions of modules before installing latest dev versions.

Greg Boggs’s picture

I'll try again from a fresh install with the latest dev of all modules. I've committed two patches and I'd like to make sure other patches didn't break this one.

Greg Boggs’s picture

Issue summary: View changes

Updated incorrect file path

David_Rothstein’s picture

Issue summary: View changes
FileSize
3.93 KB
diff --git a/media_colorbox.module b/media_colorbox.module
old mode 100644
new mode 100755

These file permissions changes should not be in the patch.

Here's a reroll without them. (No other changes.)

pinkonomy’s picture

I finally managed to make this work by using the suggested version of Media colorbox and enabling the Media WYSIWYG View Mode module and also the Colorbox under the admin/structure/file-types/manage/image/file-display/colorbox.

DamienMcKenna’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev

So does #25 mean that this does actually work?

"you MUST TOTALLY uninstall previous versions of modules before installing latest dev versions" means that an update script is needed.

moonray’s picture

Media WYSIWYG View Mode module is deprecated (well, removed really).
I could not get this to work with file_entity module 7.x-2.0-beta3, media module 7.x-2.0-beta8+2-dev and colorbox 7.x-2.12.

Greg Boggs’s picture

I believe you may be correct in that this module no longer works with the latest release of the media suite for D7. I opened an issue in the Colorbox module because Colorbox is 95% there now that Media switched to using built in Image fields, but that ticket got no attention. So, I believe the path forward is either to update this module to work with the latest media suite, or to write a small patch for Colorbox to fix video support as a part of Colorbox.

~Greg

moonray’s picture

Status: Needs work » Needs review
FileSize
2.57 KB

Attached patch fixed the problems I was having. The previous patches don't seem to have any bearing on the problem anymore.