Creating a simple video gallery using Drupal 7

As a side project, I’ve been looking at Media Uploads in Drupal 7. I am interested in using Media as a sort of asset management system at a machine level with web services allowing for the ingestion and listing of files. Anyhow as a side experiment, I wanted to take the idea of a video gallery using the Youtube and Vimeo Media modules.

In the tutorials that I’ve seen, the gallery often links back out to the original URL but what if the listing needs to link back to a node. It is not much but I did find  away of making the link work. I like the fairly simple listing of the preview, a title and associated tags. The preview and title are obvious (and the listing could be extended by adding in a description as well.) but the tags could be used for categorising the collection folksonomically.

As well as Media, Media_Youtube, Media_Vimeo, I used Taxonomy and Views 3.

The first step was to create a video content type to take an embed url from the services and put it into Drupal and allow the user to add in a title, a description and a limited number of tags to define contents by creating a form and having the form save the node. The file URL needs to be saved as a file entity since that is what Media 2 now uses. When the form is saved, it creates a node with the url. Using the theme() functions in the templates (thanks to Finn at Ecobee.coop for helping me with this bit), the video stream can be shown using your own template. If you just use the standard node template which comes out of the Drupal box, then you do not need to worry about this at all.  So that sets up the individual nodes which have videos and descriptions of them in. But how to view them?

Well that is where views comes in. I created a new view call videos/all and used the fields to select all videos at that url. I also set up a contextual filter to query the videos which were set up with tags against them to filter on the tag term and return all associated video type nodes. The default is set to show all if there are no videos with a term.

The one issue that I did find with this was if I wanted to have the video itself linked to the node, not just the title (which can be set when you call the title as a field). I had to use the content:NID field which is excluded from the display.

In the content:Video field, I set up a link which referenced the content:NID  value in the link option, had it replace the spaces with dashes and use an absolute link to provide the URL so that a preview image could be used as a link as well like Vimeo or YouTube where you have both sorts of links in the galleries.

(Another long-winded way of doing this is using the global PHP and using drupal_lookup_path() to turn the node id into a URL but you shouldn’t need to do this. )

Using these simple modules, you can create a simple Video gallery that allows you to show videos from the various web services using the Media modules. I am sure that there are other ways of doing the same thing. I am sure that I will be exploring this more as I am hoping to use Media for a variety of other projects.

4 Comments

  • I would be interested to see where you take this project in the near future and what your ultimate plans for it are.

  • iain_emsley wrote:

    Hi Rich,
    My current plans are that it is integrated into another project. I posted it as something that might be of interest but I will probably develop it in some way in the next few months.

    Iain

  • Hello, I’m Hugo from Spain and I need your help. I want to do the same video gallery in my Web page. I followed your instructions until I struck with this:

    “In the content:Video field, I set up a link which referenced the content:NID value in the link option”

    I go to Content:video – rewrite results – output this field as a link –

    Link Path: ¿?¿?¿?

    Please help me, Thank you very much

  • Ok I solved the problem. I had to rearrange the fields.

    Field content: nid must be before field content: video !

Leave a Reply

Your email is never shared.Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.