Hello,

I have a content type that includes a Kaltura Media field. When a user creates this content they're able to upload multiple images, video and audio using the Kaltura widget. Including this field in my view displays a thumbnail for each uploaded media. I'd like to control/limit how many thumbnails are displayed. Any ideas?

Thanks!

Comments

j3030’s picture

I found a fix, although I'm not sure it's the best way. I'm overriding the function, theme_field_kaltura_formatter_thumbnail, in my template.php.

Here's the original theme_field_kaltura_formatter_thumbnail (defined in kaltura/plugins/field_kaltura/field_kaltura.module):


function theme_field_kaltura_formatter_thumbnail($element) {
     return kaltura_get_thumbnail_display($item, $teaser, $field);
}

And here's the orginal kaltura_get_thumbnail_display (also defined in kaltura/plugins/field_kaltura/field_kaltura.module):


function kaltura_get_thumbnail_display($item, $teaser, $field) {
  $size = array(
    'width' => (!empty($field['thumbsize_width']))? $field['thumbsize_width']: NULL,
    'height' => (!empty($field['thumbsize_height']))? $field['thumbsize_height']: NULL,
  );
  if (!$size['width'] && !$size['height']) unset($size);
  $entries = explode(',', rtrim($item['value'], ','));
  $all_field = '';
  if (is_array($entries) && count($entries)) {
    foreach ($entries as $entry_id) {
      if (!$entry_id) continue;
      $mynode = node_load(kaltura_get_node_for_mix($entry_id));
      if ($mynode) {
        if ($mynode->type == 'kaltura_entry') {
          $all_field .= '<div class="field-entry-'. $entry_id .'">'. theme('node_kaltura_entry_thumbnail_url', $mynode, $teaser, FALSE, $size) .'</div>';
        }
        else {
          $all_field .= '<div class="field-entry-'. $entry_id .'">'. theme('node_kaltura_mix_thumbnail_url', $mynode, $teaser, FALSE, $size) .'</div>';
        }
      }
    }
  }
  $text = $all_field;
  return $text;
}

So I ended up taking the contents of kaltura_get_thumbnail_display and throwing it in mytheme_field_kaltura_formatter_thumbnail, adding code to break out of a loop after it reaches a set limit.

The final result was placed in my template.php :


function mytheme_field_kaltura_formatter_thumbnail($element) {
      
  // I'm combining two functions, so I mapped the arguments originally used in the call to kaltura_get_thumbnail_display 
  // to the variables used in kaltura_get_thumbnail_display. (Renaming variables might have introduced errors.)
  $item = $element['#item'];
  $teaser = 0;
  $field = $element['#item']['#kaltura_field'];
  
  // initialize a variable to track the loop iterations
  $count = 0; 
  
  // initialize the default number of thumbnails to display
  $limit = 1; 

  // set the number of thumbnails to display for my content type.
  if($element['#type_name'] == 'my_content_type') {
    $limit = 3;
  }
  
  $size = array(
    'width' => (!empty($field['thumbsize_width']))? $field['thumbsize_width']: NULL,
    'height' => (!empty($field['thumbsize_height']))? $field['thumbsize_height']: NULL,
  );
  if (!$size['width'] && !$size['height']) unset($size);
  $entries = explode(',', rtrim($item['value'], ','));
  $all_field = '';
  if (is_array($entries) && count($entries)) {
    foreach ($entries as $entry_id) {
      if (!$entry_id) continue;
      $mynode = node_load(kaltura_get_node_for_mix($entry_id));
      if ($mynode) {
        if ($mynode->type == 'kaltura_entry') {
          $all_field .= '<div class="field-entry-'. $entry_id .'">'. theme('node_kaltura_entry_thumbnail_url', $mynode, $teaser, FALSE, $size) .'</div>';
        }
        else {
          $all_field .= '<div class="field-entry-'. $entry_id .'">'. theme('node_kaltura_mix_thumbnail_url', $mynode, $teaser, FALSE, $size) .'</div>';
        }
      }

      // increment our $count variable
      $count += 1;      

      // If we've reached our limit then break out of the loop
      if($count >= $limit) {
         break;
      }
      
    }
  }
  $text = $all_field;
  return $text;
  
}