Hi,

I'm using videojs with theme() function (see readme of videojs).
All is working good except for poster :

In videojs.theme.inc file, inside videojs_preprocess_videojs() function we can see

...
// Add the defaults to $vars['attributes'] and merge with $vars.
$options = videojs_utility::getDisplaySettings($vars['attributes']);
$vars = array_merge($vars, $options);
$vars['items'] = array();
$vars['tracks'] = array();
$vars['poster'] = NULL;
...

then after we can see

...
// Turn the poster image URI into a URL, if it isn't an URL already.
  if (!empty($vars['poster']) && strncmp($vars['poster'], 'http://', 7) !== 0  && strncmp($vars['poster'], 'https://', 8) !== 0) {
    if (empty($vars['posterimage_style'])) {
      $vars['poster'] = file_create_url($vars['poster']);
    }
    else {
      $vars['poster'] = image_style_url($vars['posterimage_style'], $vars['poster']);
    }
  }
...

That mean test condition is never reached ! So never output poster because of $vars['poster'] is always null

My working fix :

I filled a "poster" key inside $vars['attributes'] array (because poster is outputted as an attribute :)) before calling theme('videojs', $items)

Then I changed reference to $vars['poster'] with $vars['attributes']['poster']
(so $vars['poster'] is passed to template, with correct uri)

like that

  // Turn the poster image URI into a URL, if it isn't an URL already.
  if (!empty($vars['attributes']['poster']) && strncmp($vars['attributes']['poster'], 'http://', 7) !== 0  && strncmp($vars['attributes']['poster'], 'https://', 8) !== 0) {
    if (empty($vars['posterimage_style'])) {
      $vars['poster'] = file_create_url($vars['attributes']['poster']);
    }
    else {
      $vars['poster'] = image_style_url($vars['posterimage_style'], $vars['attributes']['poster']);
    }
  }

What do you think about this ? Dis I missed something ?

Thanks

Comments

rroblik’s picture

Issue summary: View changes

typo

dkingofpa’s picture

Status: Active » Closed (works as designed)

$vars['poster'] is set within the foreach block.

  // Add the defaults to $vars['attributes'] and merge with $vars.
  $options = videojs_utility::getDisplaySettings($vars['attributes']);
  $vars = array_merge($vars, $options);
  $vars['items'] = array();
  $vars['tracks'] = array();
  $vars['poster'] = NULL;

  foreach ($items as $item) {
    if (empty($item['filemime'])) {
      continue;
    }

    if (!isset($codecs[$item['filemime']])) {
      // check for image file and add in it as poster
      if (strncmp($item['filemime'], 'image/', 6) === 0) {
        $vars['poster'] = $item['uri'];
      }

You can add a poster image by implementing hook_preprocess_videojs() in a module. Here's some psuedo-code for doing this...

function mymodule_preprocess_videojs(&$vars) {
  $image = file_load(4);
  $poster = array(
    'uri' => $image->uri,
    'filemime' => $image->filemime,
  );
  $vars['items'][] = $poster;
}

The "Example" section in the module's README.md can also provide more details about the structure passed to the theme function.