With file_entity + media, file entities are often displayed in different contexts. We need to be able to apply core image styles to images that are file entities; the default view modes are insufficient. For example, if you have a "square_thumbnail" image style, which file entity view mode does it correspond with?
Basically, there should be a file_entity view mode for each core image style. Adding image styles as file view modes means that, for as many image styles as a site has, you can always format a media image with it.
The attached patch does exactly that. File entity view modes based on core image styles are disabled by default, and can be enabled via checkboxes in the "custom display settings" collapsible fieldset on the "manage display" tab for file entities.
Comment | File | Size | Author |
---|---|---|---|
#13 | media-override-formatter-field.png | 49.5 KB | mrfelton |
#13 | media-override-wysiwyg.png | 60.19 KB | mrfelton |
#10 | file_entity-override_image_style.patch | 2.72 KB | effulgentsia |
#9 | rendered file - override image style (1).png | 84 KB | becw |
#9 | rendered file - override image style (2).png | 88.67 KB | becw |
Comments
Comment #1
Dave ReidMy only concern is do the view modes automatically set the respective image style in the file display settings? Or would they need to be configured manually?
Comment #2
becw CreditAttribution: becw commentedWell, I could make that happen.
Comment #3
becw CreditAttribution: becw commentedHere's one way to do it. This patch checks for empty settings and sets defaults both on file display and on creating the file entity formatter settings element. Not very pretty, but it works.
Comment #4
becw CreditAttribution: becw commentedI'm going to re-test this patch. It would be extremely handy to have a way to add view modes on file entities, and this patch coordinates file entity view modes with image styles and displays image files using the matching image style automatically.
Comment #5
becw CreditAttribution: becw commented#3: 1244476-3-file_entity-image_style_view_modes.patch queued for re-testing.
Comment #6
Dave ReidFile entity has switched to a 7.x-2.x branch and the 7.x-1.x branch is no longer used. Please make sure to update your Git clones.
Comment #7
fabsor CreditAttribution: fabsor commentedThis patched worked well when I tested except for two things:
* Things fail horribly if you for some reason don't have image module enabled. I have added a check for that.
* In order for the image to be rendered automatically when new image styles are added, we need to set the status to enabled in file_displays_alter.
Comment #8
effulgentsia CreditAttribution: effulgentsia commentedI disagree with the File entity module creating a view mode for each image style. Instead, I think the goal of making it easier for admins to use their image styles on file fields can be achieved via an "Image style override" setting on the "Rendered file" formatter. Will try to post a patch showing this in the next couple days.
Comment #9
becw CreditAttribution: becw commented@effulgentsia -- ok; that will make it even easier for users to format images in the way they expect when they're getting started.
Here is a quick mockup of what it might look like.
Comment #10
effulgentsia CreditAttribution: effulgentsia commentedTo elaborate on #8, the reasons I disagree with *automatically* making a view mode for each image style is that:
I think the underlying desire in this issue is to make it easier for the administrator to choose an image style when configuring the display of a file field, without needing to go through a bunch of hassle of adding and configuring a new view mode to do so. So, here's a patch that implements #8/#9.
For use-cases where creating new view modes is needed, modules like Display Suite let you do that.
Comment #11
effulgentsia CreditAttribution: effulgentsia commentedChanging issue title to reflect #10, but if anyone disagrees with this approach, please say so.
Comment #12
mrfelton CreditAttribution: mrfelton commentedSlightly different, but related - Also see the Formatter Field module, which can let users select formatter options per entity.
Comment #13
mrfelton CreditAttribution: mrfelton commentedConceptually I really like what this patch aims to do. It doesn't yet work properly in a variety of situations. Here are some examples.
1) Configuring the display on the Manage Fields tab for a content type. The admin UI works very well, but overriding the image style does not change the output of the image when the node is rendered.
2) Configuring the display of an individual image uploaded to a node by using the Formatter Field module. See attached screenshot. Again, the admin UI works, but there is no change to the image when displayed. Also, there is a PHP warning on the node/edit form.
3) Configuring a meda embed when embedding images into content through the WYSIWYG. See attached screenshot. The options to override the image style are not presented at all.
I should probably note that I have the following other patches applied to File Entity:
and Media:
Comment #14
mrfelton CreditAttribution: mrfelton commentedActually, it does work both from Manage Fields, and in conjunction with the Formatter Field. The issue was I had the view mode set to 'Original' and then tried to override the style on that. That doesn't work because of your check for
!empty($element[$delta]['file']['#style_name'])
. The Original view mode doesn't have an assigned Image Style. So as is this patch will only let you override the display for view modes that have an assigned image style. In some ways it makes sense, but in other ways it is confusing. Just because the site builder configured the field to display the Original, does that mean the user shouldn't be able to override the output?Also, I think we might want to consider providing the ability to limit the available image styles on a per field basis. Not all image styles make sense in all situations, and you wouldn't want to provide content editors with options that make no sense or give them the ability to break page. This is probably really only an issue when using Formatter Field.
Comment #15
Eyal ShalevThe patch is really great and such but when is it pushed to the official release of file_entity?
It's been almost a year since this patch was offered and more than a year since this issue was created.
P.S.
If and When this patch is pushed I think mrfelton problem should also be handled (comment #14) by either overwriting the image style even if none is used in the file display or by adding another option to the image style select list in the file display form ('decided in the field formatter').
Comment #16
caschbre CreditAttribution: caschbre commentedI think I'm running into this issue while attempting to render image file entities in a View. I'm attempting to create a View that renders the image file of an image file entity. I'm only allowed to choose View Modes and not Styles.
I applied this patch but it didn't seem to help with the View. Should this patch work in this situation?
Comment #17
RobW CreditAttribution: RobW commented@caschbre: If "Styles" == Styles module, its use is deprecated. If "Styles" == image styles, currently you'll want to configure your image styles per view mode, and then use the view modes in views. If you need a new view mode for your view, check out the Entity View Modes module.
I can see a use for this override functionality, but I'm not sure it needs to be in File Entity module. It's basically a shortcut around the best practice of configuring all formatters per view mode, aka per context. If someone were to port Effulgentsia's patch to a new module, ++. For file entity, my vote is works as designed/ won't fix, unless this addresses something besides overriding image styles for image formatters in view modes.
Comment #18
caschbre CreditAttribution: caschbre commentedIn my case, styles = image styles.
I'm of similar opinion as effulgentsia in #10. Creating view modes simply to render an image using a different image style doesn't quite seem right. I may have 20 image styles to render the same image in different use cases but creating 20 view modes to handle each image style seems excessive.
I could see situations where I'd want to render the same view mode in different scenarios where all I change is the image style used.
Comment #19
RobW CreditAttribution: RobW commentedIn the case of a file field that can accept multiple file types, wouldn't you then want to display each file type at that image style size, and isn't that a good reason to create a new view mode? Not attacking, just wondering.
Comment #20
caschbre CreditAttribution: caschbre commentedThat's a good point Rob. I think in that scenario a view mode might be the best way. In my current situation, I'm simply dealing with image file types so I hadn't really considered other file types. I can see the case for both options... which allows the choice / control up to the site builder.
Right now I'm utilizing the entity view module to create a new view mode that applies 'only' to the image file type. Then in that view mode I can choose the image style I want. I'm having to do this for each image style I want to use.
I'm rendering image files in a View. Ideally, I'd love to be able to simply render the image file and choose which image style to use for that particular view display. What I'm having to do is create and configure the view mode, then choose that view mode in the view display.
Comment #21
ParisLiakos CreditAttribution: ParisLiakos commented#10: file_entity-override_image_style.patch queued for re-testing.
Comment #22
knalstaaf CreditAttribution: knalstaaf commentedWhen using the File Entity Link module, the patch of #10 stops working within a regular node and in Views. Not sure if it the bug (if you can call it that) resides in the patch above or the mentionned module.
#1830444: Overridden image style ignored
Comment #23
joelcollinsdc CreditAttribution: joelcollinsdc commentedI'd like to add my opinion that forcing all images into a pre-defined set of view modes (that apply to ANY file entity type) seems crazy to me. Even worse is those view modes store settings like if the media item is linked or not! If you continued down this path, you could have view modes for things like:
teaser
teaser - linked
thumbnail
thumbnail - linked
original
original - linked
And many of these only apply to a specific type of media like video. While I like the direction that the view modes is going, I think the approach needs to be re-evaluated.
FWIW, I think the approach I'm going to attempt to take is create some standard view modes for images and attempt to use image resize filter for the rest. Unfortunately that integration is broken as well right now.
Comment #24
aaron CreditAttribution: aaron commented#10: file_entity-override_image_style.patch queued for re-testing.
Comment #26
Devin Carlson CreditAttribution: Devin Carlson commentedThe rendered file formatter was removed in #2061625: The 'Rendered file' formatter should not be available as a checkbox on the 'Manage file display' tab.
Comment #27
Pere OrgaI still see the rendered file field formatter. Was that patch removing another thing? e.g. the rendered file field formatter for fields of a file entity.