Changing the regular expression in wysiwyg-media.js's Drupal.wysiwyg.plugins.media.detach() allowes to use files of the type application (e.g. PDF's) in the wysiwyg.

How to

  • Add the file type application to the variable media__wysiwyg_allowed_types.
    Use aarons patch here #1016376-58: Expose the media types allowed for WYSIWYG variable in the UI or this php snipped:
    <?php
    variable_set
    ('media__wysiwyg_allowed_types', array(
       
    0 => 'application',
       
    1 => 'audio',
       
    2 => 'image',
       
    3 => 'text',
       
    4 => 'video',
       
    5 => 'default',
    ));
    ?>
  • Configure the file dispplay of the file type application e.g. use the Generic file formatter for the display Link.

If media is configured that way and the regular expression patch is applied you should be able to open the wysiwyg-media-browser, select e.g. a PDF file and choose Link as display to add it into the editor.

What the patch does:
It changes the current regular expression
/<img[^>]+class=([\'"])media-image[^>]*>/gi
to this one
/<img[^>]+class=([\'"]media-image |[^>]*\smedia-image\s|[^>]*\smedia-image[\'"]|[\'"]media-image[\'"])[^>]*>/

Reason to do so is, that if a file of type application is inserted the order of the added classes is different (file-icon occurs before media-image).
The old regexp olny matches if media-image is the first class in the attribute.
The new regepx doesn't care about the position of media-image as long as it's really this class and not e.g. media-image-evil what matched on the old regexp.

Matches:
<img title="application/pdf" src="modules/file/icons/application-pdf.png" class="media-image" alt="">
<img title="application/pdf" src="modules/file/icons/application-pdf.png" class="media-image file-icon img__fid__5988 img__view_mode__media_link" alt="">
<img title="application/pdf" src="modules/file/icons/application-pdf.png" class="file-icon media-image img__fid__5988 img__view_mode__media_link" alt="">
<img title="application/pdf" src="modules/file/icons/application-pdf.png" class="file-icon img__fid__5988 img__view_mode__media_link media-image" alt="">
Doesn't matche:
<img title="application/pdf" src="modules/file/icons/application-pdf.png" class="media-image-evil img__fid__5988 img__view_mode__media_link" alt="">
Files: 
CommentFileSizeAuthor
#17 1415568-d7-1.patch758 bytesasgorobets
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]
media-change-wysiwyg-regep-to-allow-other-file-types.patch758 bytesdas-peter
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Comments

Status:Needs review» Reviewed & tested by the community

works as advertised!

Could you provide more detailed instructions on:

Add the file type application to the variable media__wysiwyg_allowed_types.

?

Thanks so much!

EDIT: Realized I'm using the 7.x-1.0-rc3 version of the media module. Will this patch work for that version as well?

that requires #1016376-58: Expose the media types allowed for WYSIWYG variable in the UI. no idea if it will work on th 7.x-1.x branch.

@areikiera: As far as I remember in 7.x-1.x the only "problem" was the configuration and not any regexp - at least one of our customer's still using this version and there it works. But it could be that I made some changes to the module.
However, aaron already pointed to the root issue - depending on how fit you are in php you can solve this without an UI. Just execute following php snippet (add it to your install profile, to your module installation, execute it with devel or whatever):

<?php
variable_set
('media__wysiwyg_allowed_types', array(
   
0 => 'application',
   
1 => 'audio',
   
2 => 'image',
   
3 => 'text',
   
4 => 'video',
   
5 => 'default',
));
?>

@das-peter, thank you so much for the guidance! I've executed the code you provided above (through the execute PHP code through Devel [does it matter on which page I execute it? I did it from the home page.]) and implemented the patch posted by aaron on http://drupal.org/node/1016376#comment-5400668 (though I had to apply it manually as the lines didn't match up).

Still no luck. The UI on the Media Browser settings showed up, but only listed 4 options even after running the PHP code: Image, Audio, Video and Other. I assume that means that my PHP code didn't properly execute or I would see Application, Text and Default (I don't see 'Other' in your list) as well, right?

Could the variable name be different for the 7.x-1.0-rc3 version?

Thank you so much for any help! If I've gotten too far away from the main topic, I'm happy to post a different support request.

@areikiera: It doesn't matter on which page you execute the php code and not really a surprise that aarons patch didn't apply cleanly, the patch is for 7.x-2.x - but this definitely shows how decided you are ;)
Now, what's actually the issue you experience? That there are not all the options in the UI is just because the fact that you use 7.x-1.x, at least as far I know.

Applies cleanly, including after #1016376: Expose the media types allowed for WYSIWYG variable in the UI and does the trick of letting me embed a PDF.

However I did find a few quirks for the other patch (see comment #59). Maybe those needs to be addressed first before this one can be committed as well.

Component:Code» WYSIWYG integration

I'm trying to replicate this bug for Media 2.x with the latest code and I seem to be unable to do so.

Status:Reviewed & tested by the community» Needs work

I'm trying to replicate this bug for Media 2.x with the latest code and I seem to be unable to do so. This JavaScript function isn't even firing for me. I followed the steps to reproduce in the original report.

Status:Needs work» Needs review

@Dave this patch fixes so that when you want to edit an existing node, the Media placeholder code is there. Without it, all you get is an <img...>-tag.

Simply try and edit an existing node without, and with, the patch and look at the source code and you'll spot the difference.

One difference I see though is that when you edit the node, you just see the small PDF icon, but when it is viewed you get icon + linked file name. Should be the same in the editor too.

Status:Needs review» Needs work

Hm, someone managed to set the wrong status. I swear it wasn't me...

Priority:Normal» Major
Issue tags:-D7 stable release blocker

De-prioritizing this for a 1.0 release blocker but bumping to major.

Status:Needs work» Reviewed & tested by the community

I am still able to reproduce the bug, and this patch still fixes it for me.

StatusFileSize
new758 bytes
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]

I rerolled it for current dev version and it works for me.

Hm, how about adding the new application type to media_variable_default() to make this patch complete.

#17: 1415568-d7-1.patch queued for re-testing.

Status:Reviewed & tested by the community» Fixed

I was able to reproduce this.

@Dave detach your editor when you have selected a lets say a pdf and compare.
without patch: just <img> tag
with patch: json

@Eric_A see #1016376: Expose the media types allowed for WYSIWYG variable in the UI

thanks fix commited!

Status:Fixed» Closed (fixed)

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

Issue summary:View changes

Updated issue summary.