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.
View modes are a pain in the butt when they're hardcoded into something. In particular the media_get_thumbnail_preview which is locked on to the 'Preview' view mode.
Comments
Comment #1
reubenavery CreditAttribution: reubenavery commentedFor your consideration, here is a patch that uses a variable_get call instead of a hardcoded 'preview' to render files in the media browser.
Comment #3
reubenavery CreditAttribution: reubenavery commentedblah here's another attempt..
Comment #4
slashrsm CreditAttribution: slashrsm commentedComment #5
DravenDev CreditAttribution: DravenDev commentedeh probado el parche pero aún la muestra de imagenes previas no se muestran en tamaño thumbnail esto es incomodo para poder trabajar, como puedo corregir este problema
Comment #6
reubenavery CreditAttribution: reubenavery commentedRe-rolled patch against latest dev release.
Comment #7
ParisLiakos CreditAttribution: ParisLiakos commenteddoesnt the media_wysiywg_view_mode module solves this issue?
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedHere is a much more comprehensive patch that makes this a setting for widgets and an argument that can be passed in.
Comment #10
merlinofchaos CreditAttribution: merlinofchaos commentedUpdate to fix a bug I found with newly uploaded files.
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedUpdate to fix the notices. I'm not sure why the test is failing, it doesn't SEEM related. :(
Comment #13
tea.time CreditAttribution: tea.time commentedUpdated patch from #11 to apply to latest 7.x-2.x-dev. A couple of notable changes:
Merlin's patch added a Media Browser field widget setting to allow selecting a view mode for previewing files selected in that field. I added a new view mode called "Field preview" which is used as the default here. This allows easily rendering the selected files' preview differently than the grid of thumbnails used in the media browser.
I also noticed that the view mode thus selected for the preview in a field was being used for the Media Browser for that field as well. This is because the widget setting was also passed to the JS and ended up in the querystring params for opening the browser. For the sake of differentiation mentioned above, I moved this slightly in the form element's array so it won't be passed to the JS.
Comment #14
jurgenhaasWhat is the reason that media_get_thumbnail_preview() is using file_view_file() instead of entity_view('file')? The reason I'm asking is that we would like to include other fields into the thumbnails (e.g. title) so that better media selection will be possible by the end user.
Comment #15
Devin Carlson CreditAttribution: Devin Carlson commentedThanks for the patches! I think it might be best to move the addition of a new view mode and the UIs for selecting it in various places to a separate issue and add some tests.
The attached patch makes the changes to
media_browser()
,media_browser_build_media_item()
,media_get_thumbnail_preview()
andtemplate_preprocess_media_views_view_media_browser()
necessary to allow developers to customize the view mode used even if it is a bit of work:Thumbnail page and file edit page-
hook_form_alter()
;Media element -
hook_element_info_alter()
with a#process
callback.Media browser -
hook_media_browser_params_alter()
Comment #16
Devin Carlson CreditAttribution: Devin Carlson commentedOpened #2475613: Add UI for configuring the view mode used to display files inside the media browser to deal with adding additional view modes and a UI to configure which view mode to use when rendering files inside of the media browser.
Committed #15 to Media 7.x-2.x.