Currently in both 7.x-2.3 and 7.x-3.x the following code is present in the videojs.tpl.php file:
print check_plain(file_create_url($item['uri']))

I believe that this processing should be done within the theme function rather than the tpl file and a new element should be added to the item array, something along the lines of:

$item['src'] = array('raw' => file_create_url($item['uri']), 'safe' => check_plain(file_create_url($item['uri']));

The template file would then look something like this (note that I have changed the $item['videotype'] code too; this change should be applied to any processing currently done in the tpl, not just the video uri):

<source src="<?php print $item['src']['safe']; ?>" type="<?php print $item['videotype']['safe'] ?>" />

This would tidy up the tpl file while still giving the user the option of accessing the other variables such as $item['uri']. The main benefit however would be that other modules could override the variable through theme override functions without having to reproduce the tpl file itself.

For a bit of background, I'm currently writing a module that would allow Video.js to serve media stored in Drupal's private file system using one-time, unque, user specific source URLs. At the minute, no matter the approach I use I'm still going to have to reproduce the tpl file somewhere in order to change the code I initially mentioned. Ideally, if this processing was done in the theme function I could override any variables I wanted in my module without having to touch a tpl file.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit’s picture

Your code snippets look fine, although I think it is nicer to rewrite it such that file_create_url() is just called once. Could you make a patch for it? I will commit it to 7.x-3.x, so please use that branch as your base version.

jamiehollern’s picture

No problem, I'll get a patch done in the next day or two for version 7.x-3.x.

Edit to say that I agree with your point regarding file_create_url, obviously the code was just used as an example. I'll make sure it's as efficient as possible.

jamiehollern’s picture

Here's the patch as promised. I've tested it and it seems to work fine. One thing to note is that I've left some of the "tracks" stuff alone as I wasn't exactly sure how it worked. For example:

print check_plain($track['kind'])
print check_plain($track['label'])
print check_plain($track['langcode'])

jamiehollern’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, videojs-remove-file_create_url-2069865-1.patch, failed testing.

jamiehollern’s picture

Version: 7.x-2.3 » 7.x-3.x-dev
Status: Needs work » Needs review
FileSize
3.62 KB

It seems the patch failed because I forgot to change the version. Trying again.

jamiehollern’s picture

Duplicate.

Jorrit’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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