When I try to upload a file (image or other type) via the "add media" button in ckeditor. After choosing the file and selecting default format, I only see a generic file icon instead of a linked filename with generic file icon.

Members fund testing for the Drupal project. Drupal Association Learn more


filsterjisah’s picture

Status: Active » Needs review
813 bytes

in sites/all/modules/contrib/ckeditor/plugins/media/library.js function stripDivs seems to also strip spans (which is wrapper arround the format output) and look for img tag (our generic icon).

I've added a patch, please test & review.

kevinchampion’s picture

This works for me to give me both the generic icon and linked filename.

kevinchampion’s picture

On second look, while this works to make the generic icon and linked filename appear and be formatted correctly, it doesn't address the fact that the document is not being tokenized like an image is. The reason the above patch works is because when documents are embedded they are just printed as html. The javascript goes through a step to strip out any surrounding elements around the image, in order to only work with the image element, in order to tokenize it. So, the above works if you don't mind document embeds just being html and not media tokens.

The attached patch includes a method for using the above to keep the plugin from stripping out the filename link, and also converting the document to a media token. It does this by removing the span wrapper and filename link when the editor detaches, and adding back the span wrapper and filename link when the editor attaches.

With this in place, it is then just a matter of working upstream to get the icon and filename link to appear properly when the document is rendered via theme file_link on output to the page. It looks like this may be able to be accomplished by hooking into file_link or media's own hook_media_token_to_markup_alter().

iSoLate’s picture

Doesn't work for me. Added a patch for my problem which was that I couldn't show any file at all using the ckeditor together with the media module.

caktux’s picture

Patch in #3 works great here.

SocialNicheGuru’s picture

conflict with this ckeditor patch to fix media issue:

PI_Ron’s picture

Issue summary: View changes

Has anyone got ckeditor + media successfully embedding files/documents other than images?

wwalc’s picture

I'd like to encourage everyone to test instead the following code: #2159403: Make CKEditor plugin system modular and clean

hkirsman’s picture

PI_Ron, got the file embedding working Media dev + Media CKEditor dev + CKEditor dev!