Drupal 7 out the box offers a good implementation for uploading media, but it has three significant challenges.
Challenge 1: Files should be entities
In Drupal, files should be entities so you can add additional fields to the file type. As an example, when you upload an image you will want your standard image alt attribute, which specifies alternate text for an image, if the image cannot be displayed, or the user is using a screen reader. But you may want to have additional fields, such as photo credit or image caption.
Challenge 2: Reusable media
A lot of times, the same media will be used throughout the site. Unfortunately Drupal's default implementation does not allow for media to be selected again when creating/updating content.
Challenge 3: Multimedia assets
Out of the box, Drupal 7 does not include a way of including multimedia files such as videos and audio.
So how do you vanquish these challenges? Let me introduce you to the Media module.
All of the challenges above can be resolved with the implementation of Media, a fantastic module that is a replacement for the core upload field, allowing site editors to upload, manage, and reuse files and multimedia assets.
What are Media’s key features?
The Media module has four key benefits:
- A unified interface for adding new media, or reusing existing media.
- The ability to upload remote media from sites like YouTube and Vimeo.
- It can embed files into any textarea using a “WYSIWYG” editor, an acronym for "what you see is what you get," which refers to an editor that allows the user to work in a format that’s very close to what the published version will look like.
- Drag and drop upload is possible, by adding another module.
What else can we do with Media?
We can use Media within a WYSIWYG content area.
A huge benefit of Media: you can use it to embed media in a WYSIWYG interface on your Drupal site. If you look at the source of the embedded file, you will see that Media uses its own markup:
[[{"fid":"1066","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"Mary's Nipple Grand Targhee","field_file_image_title_text[und][0][value]":"Mary's Nipple Grand Targhee"},"type":"media","link_text":null,"attributes":{"alt":"Mary's Nipple Grand Targhee","title":"Mary's Nipple Grand Targhee","height":735,"width":1200,"class":"media-element file-default"}}]]
Because Media uses its own markup, we can update the media object and keep the same file ID (FID).
Extend Media with patches
In addition to uploading Media into an WYSIWYG interface, we can also use it to allow an image to be clickable.
To do this, use the following patch: missing-media-attributes, available in this post. Without this patch the link that is wrapped around the image would be stripped when it is rendered on the front end.
Please note that in the latest edition of Media (7.x-2.0-beta1), this patch does not seem to be required for Media to include a wrapping link.