Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hey there and thanks for this nifty little helper. I found it to be a great alternative to the somewhat blown media thing.
However, it would be awesome if the available video formats could be configured in the backend.
Right now I had to hack youtube.inc to add my desired dimensions manually, which is evil, of course.
In case anybody else needs to quickly add another size: just add your desired format to the array found in youtube_size_options() inside youtube.inc.
Comments
Comment #1
jenlamptonThis is reasonable, YouTube allows custom dimensions and I'd like the field formatter to do the same.
Comment #2
guschilds CreditAttribution: guschilds commentedI too thank you for this module. Media and Media:YouTube was way more than I needed and this was perfect.
Like klickreflex, I needed to have more freedom with the video dimensions so I implemented the attached patch. It basically replaces all uses of youtube_size with youtube_width and youtube_height. Could probably remove a few existing functions if this code sticks. Also worth noting: I did not touch anything with thumbnail formatting. Anyway, happy to hear criticism.
For all using this module and/or patch: the dimensions are altered as field formatters.
Thanks again,
Gus
Comment #3
enzipher CreditAttribution: enzipher commentedHey,
I needed this feature as well, however, I needed multiple size options so I added a textarea in the admin config where the user can enter an unlimited number of sizes.
From what I can tell guschilds patch in #2 only support one custom size.
There might be room for improvements, but I hope this patch can be of use.
Cheers,
Comment #4
guschilds CreditAttribution: guschilds commentedThe patch I created allows the user to enter one size per View Mode per Content Type. The choices are not stored on the module settings page, but on the field formatter settings for a given field. To change the output video dimensions of a video field:
This is essentially how the dimensions are changed in the original module and in #3 patch as well, just providing free range rather than selection from a list of pre-defined choices (whether they be hardcoded into the module or configured on the settings page).
The downfall in my approach is that it relies on the data provider to get the dimensions of the desired aspect ratio correct for the embedded video to properly fill the video frame. Not convinced it is the better approach, but it is working well for me thus far.
Comment #5
enzipher CreditAttribution: enzipher commentedYou are completely correct in that your patch support different dimensions. I never actually tried it, so excuse me for missing that. However, I personally prefer my approach in the way that you have all sizes in one place, and when editing the display settings there is no confusion what to enter, or in this case what to choose. My patch also supports Views, which as far as I can tell yours doesn't.
In any case we're all winners. Your patch works for you and my patch works for me, and everyone else can choose what they prefer. ;)
Cheers,
Comment #6
endless_wander CreditAttribution: endless_wander commentedThanks to guschilds and enzipher for these patches. I tried both and they work well for this. Would recommend something being added to the main module to support this feature...
Comment #7
B-Prod CreditAttribution: B-Prod commentedThanks, the patch works well. It only misses a "variable_del" call in the install file for the new introduced variable "youtube_sizes".
Comment #8
chefnelone CreditAttribution: chefnelone commented@guschilds: I'm trying to apply the patch you've posted in #2 but I get this error message:
Is the patch older than the last version of the module?
Great module btw, thanks for sharing it!
Comment #9
guschilds CreditAttribution: guschilds commented@chefnelone
It was the same code, but you are right, it wasn't properly applying to the fresh download.
I went ahead and rebuilt the patch from #2. I've also removed a bit more code that is no longer necessary when the field is sized in this way. It should work for you now with 'git apply -v youtube_field-video-dimension-formatters-1485078-9.patch'.
It applies cleanly, but you may get 3 whitespace-related errors due to a whitespace at the end of three lines that are outputting a long HTML string in theme_youtube_video() of youtube.theme.inc. If anyone has a better suggestion for formatting this it is welcome.
Thanks for bringing this up!
Gus
Comment #10
chefnelone CreditAttribution: chefnelone commentedthanks!
Comment #11
AaronBaumanDoesn't seem to be working -- the video stays the same size even after i change the settings.
The height and width variables are not being saved properly in the display settings.
also, now i'm getting a php warning:
Undefined index: youtube_size in youtube_field_formatter_view() (line 229 of ...youtube.module)
Comment #12
AaronBaumancorrection: the values are being stored properly in display settings, they just aren't sent to the theme function.
this is correlated to the "youtube_size" notice mentioned previously.
line 229 "youtube_size" should be replaced with two lines for "youtube_height" and "youtoube_width"
Comment #13
guschilds CreditAttribution: guschilds commented@aaronbauman
My apologies. I had this working properly in #2's patch but missed it when recently re-creating the patch.
I've replaced line 229 of youtube.module just as you've advised. The attached patch is identical to #9 aside from the addition mentioned in #12.
I tested it quickly and it seems to work as it should. Thanks for bringing it up. I'll get this right one of these days!
Gus
Comment #14
guschilds CreditAttribution: guschilds commentedComment #15
jenlamptonI don't think I like the approach given in the latest patch.
I'd prefer to see a UI more like that on youtube.com for selecting image size.
We should add the custom option to the set-options that were available before. we should not replace the selected sizes with only the option for custom sizes.
Comment #16
jenlamptonHere's a solution that adds an additional option for a custom size.
What do you think of this?
Comment #17
guschilds CreditAttribution: guschilds commentedI think #16 is the best idea that has come from this thread. I applied the patch and it works well.
I'm not trying to steal any thunder, but there was a whitespace issue on one line. I've fixed it in the attached patch. That is the only difference.
For others trying to apply this patch, it will not apply to 7.x-1.x-alpha2, but will to the most recent 7.x-1.x branch. I'd imagine it will likely become a part of that branch soon enough.
Comment #18
guschilds CreditAttribution: guschilds commentedFWIW, I would have marked #16 reviewed & tested by the community had I not removed the white space from one line and posted a new patch.
Comment #19
AaronBauman+1 for #16 + #17
Comment #20
jenlamptonIt sounds like aaronbauman meant to change the status.
Comment #21
jenlamptonfixed and committed! Thanks for the help everyone :)