I'm trying to write a custom formatter that will allow my multi-valued file_video (filefield) to generate a playlist. I'd like to manually render the first video in the file array, then when clicking on the playlist items render that particular video in its place.

I've got Media:YouTube mixed with MediaElement.js rendered videos (using remote stream wrapper), mixed with Oembed files as values for the multi-valued video filefield. It does not appear that any one single video player solution can handle these varied use-cases, so I'm going to have to cram them together with a custom formatter of my own (including js, etc.).

The file entity managed display feature is AWESOME--the ordering of players, etc. is EXACTLY what I need for this case.

How do I process my filefield values array--or submit a single value from the array (fid?) to the File Entity module's display formatter logic?

CommentFileSizeAuthor
#2 fe_1.jpg52.55 KBdellis
#2 fe_2.jpg58.27 KBdellis

Comments

dellis’s picture

Working through this solution, part-way there. I'm using the Custom Formatters module which allows you to quickly incorporate new custom formatters for fields written in HTML+Tokens or PHP (this one is using PHP).

- I found the file_entity_field_formatter_view (hook_field_formatter_view), the call looks like this:
file_entity_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);

- returning the value of that call from the custom formatter preview screen gives me an array, so a print_r of that call shows that each file is listed in as a child of that array. If I were to instead add a "drupal_render()" around the call, it would display all of the videos in proper format as per the initial issue post

- So, to get the first value for this video field--and render it, I need to do something like this:

$element = array();
$element = file_entity_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
return drupal_render($element[0]);

- to add the other filenames into a list below the player (which will serve as the html basis for the playlist), I can do something like:

 $element = array();
$display['type'] = 'file_rendered';  // needed because the custom formatter--once selected replacing this value that this module needs
$display['settings']['file_view_mode'] = 'default';  // needed again because custom formatter doesn't have this setting
$element = file_entity_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
$output = '<div id="fe-player-wrapper"><div id="fe-player">' . drupal_render($element[0]) . '</div>';
$output .= '<ul>';
foreach (element_children($variables['#items']) as $delta) {
  $item = $variables['#items'][$delta];
  $output .= '<li>' . str_replace("%20"," ",check_plain($item['filename']))  . '</li>';
}
$output .= '</ul></div>';
return $output;

- Now obviously, the javascript, etc. parts, but this gets me started - the remaining question/challenge is how to get the javascript actions to call the page to render the next video.

dellis’s picture

StatusFileSize
new58.27 KB
new52.55 KB

Screenshot of resulting formatted video_field. An obvious problem is the YouTube video--I haven't seen human-readable information available for it yet (I don't think the Media:YouTube wrapper provides it).

dave reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
devin carlson’s picture

Status: Active » Closed (works as designed)

I don't believe this should be File entity specific - any standard file formatter (to deal with fields) should work just fine.

I suggest you take a look at the Examples module which contains some great documentation on creating file formatters.

devin carlson’s picture

Issue summary: View changes

tweak