Tech Blog :: Drupal: Impossible to set custom size for embedded video field in a view?


Aug 6 '10 1:15pm

Drupal: Impossible to set custom size for embedded video field in a view?

I have an Embedded Media youtube video field shared across multiple content types on a site, and nodequeues for the administrators to pick from these videos and feature them on various landing pages. The designs call for the videos to be different sizes on different pages - sometimes the standard 425px, sometimes 300px, sometimes widescreen 600px. When I saw the designs, I thought "I'm sure that's easy to do," and gave my approval. I'm implementing each "featured video" using a view that pulls from the respective nodequeue and displays the video as a field.

Well... I've spent hours trying to crack this nut, and my conclusion is that it's nearly impossible to do in a clean way. By clean I mean, I want to specify per view what size the video should appear. I can't set it per content type (using the backend UI) because the videos come from many content types, and if I set it by URL, there could be other videos on those pages that don't need special formatting. The settings for the field in Views only have Full and Preview, not custom sizes.

The logical approach seemed to be a hook_views_pre_render like so:
$view->field['field_video_youtube_embed']->content_field['widget']['video_width'] = 300;

That didn't work (still came out 425px), so I decided to go down an academic rabbit hole to figure out why...

The problem seems to arise with the generic content_handler_field::render() class that the field is rendered through. The object has a perfectly good $this->content_field array, which includes my modified width/height. But the function finds it necessary for some reason to get a fresh field array,
$field = content_fields($this->content_field['field_name'], $values->{$this->aliases['type']});
so the parameters are all reset. Why??

I'll just use a fields preprocessor to re-render the field. Should have done that to begin with; this study was intellectually fascinating (in a sad way) but otherwise a huge waste of time.

without seeing the actual code, not sure, but CSS and/or jQuery can make quick work of display issues - it's nice to be able to control rendering but sometimes it's easier/faster to just change the display- you will need to pick up your node id or class as a selector

I agree with the jquery statement. I've used jquery a few different times and it seems to work beautifully. I know that it doesn't degrade and would love to see more information on how to have this done in the back-end.

Here's a novel idea: maybe instead of using Planet Drupal as your persona; issue queue and complaint box you should do a search in the emfield issue queue, find the issue that relates to your problem (for example: http://drupal.org/node/668270), figure out how to fix it, and submit a patch? At the very least, following the first two would make your Planet pollution less annoying.

Seriously, the Planet is not your issue queue.

Where's that buck actually stop?

I realize you're a maintainer of the module so I'd like to add -- I tried finding that thread through various search terms - custom video size, custom size, other video size, view video size - and that post doesn't come up for any of them.

I'm a freelancer, I spent 6 hours of unbilled time trying to understand your module, isolated the problem, and posted about it. I could spend another 6 hours writing a patch, but unfortunately I don't have time right now. I would be happy to give it a shot if you point me in the right direction: is the solution another CCK formatter, or a Views field formatter, or something else?

Thanks,
Ben

I tried finding that thread through various search terms - custom video size, custom size, other video size, view video size - and that post doesn't come up for any of them.

None of those terms shows up on any emfield settings page, which is why nobody posted an issue that mentions those terms. Next time try "preview full size" or something that roughly corresponds to the module's usage of terms around the issue you're looking for.

I'm a freelancer, I spent 6 hours of unbilled time trying to understand your module, isolated the problem, and posted about it. I could spend another 6 hours writing a patch, but unfortunately I don't have time right now.

Well, since I'm getting paid so lavishly to maintain the module you're using for free... Seriously: We're all volunteers, and trust me, if you think your life is busy as a freelancer, try going from a freelancer to a 10+ person shop.

Here's a good place to look to figure out how this might be possible (and yes, it is a CCK formatter): http://drupal.org/node/92382

Alex, Thanks for the feedback. There are 322 open issues in the queue, I did search but did not find that one.
It was my understanding that Drupal Planet was an aggregator for posts about Drupal, including gripes about its challenges. Is that not your view?

Ben

There are just over 200 *active* emfield topics, and only 2/3 or so even pertain to 6.x http://drupal.org/project/issues/statistics/emfield

Ben,

Thanks for posting this message. I did a search as I had the same problem, needed/wanted to change the size of a preview. Your post was top of my google search and answered my question right away. At least I didn't have to go down that rabbit hole.

I too did a search on drupal for preview view size and didn't find the issue on emfield mentioned above. In addition your post and others comments offer a few options and possible workarounds. The issue for emfield is a year old and no suggested workarounds. Maybe there aren't any. But I'll try a few options mentioned in the post.

If you came on with a good workaround please let me know.

And thanks to all the volunteers on Drupal for the code.

Hi.
I just come into this old debate to share the solution.
I found it here : https://www.packtpub.com/article/third-party-video-hosting-on-drupal-web.... It's about the Embedded Media Field options and config ; is said that :

You can set video sizes in the next sections for full size and preview size video display. By default, videos will be displayed in full size. You can change the display to video preview or thumbnail at the display settings page, by browsing to Administer | Content management | Content types | Video | Display fields (at /admin/content/node-type/video/display).