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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

My 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?

becw’s picture

Well, I could make that happen.

becw’s picture

Here'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.

becw’s picture

I'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.

becw’s picture

Dave Reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

File 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.

fabsor’s picture

This 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.

effulgentsia’s picture

Assigned: Unassigned » effulgentsia
Status: Needs review » Needs work

I 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.

becw’s picture

@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.

effulgentsia’s picture

Assigned: effulgentsia » Unassigned
Status: Needs work » Needs review
FileSize
2.72 KB

To elaborate on #8, the reasons I disagree with *automatically* making a view mode for each image style is that:

  • View modes should represent context (e.g., preview, teaser, full, search result, etc.), whereas image styles often represent a particular formatting choice (e.g., thumbnail, small_black_and_white, etc.). So automatically creating/enforcing a 1 to 1 map for them seems wrong to me. See #1296268: Add Preview and Teaser view modes about moving our current confusing Media view modes to proper semantic file entity view modes.
  • A site can easily have 20 or so image styles, and having that many secondary tabs in "manage display" and "manage file display" gets unwieldy.
  • You don't want to necessarily configure different ways of displaying the fields attached to the file, for each image style, but that's what you need to do when you add a view mode.

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.

effulgentsia’s picture

Title: File view modes based on core image styles » Add an "Override image style" setting to the rendered file formatter

Changing issue title to reflect #10, but if anyone disagrees with this approach, please say so.

mrfelton’s picture

Slightly different, but related - Also see the Formatter Field module, which can let users select formatter options per entity.

mrfelton’s picture

Status: Needs review » Needs work
FileSize
60.19 KB
49.5 KB

Conceptually 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.

Notice: Undefined index: image_style in file_entity_field_formatter_settings_form() (line 42 of profiles/concern/modules/contrib/file_entity/file_entity.field.inc).

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:

mrfelton’s picture

Actually, 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.

Eyal Shalev’s picture

Priority: Normal » Major
Status: Needs work » Needs review

The 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').

caschbre’s picture

I 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?

RobW’s picture

@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.

caschbre’s picture

In 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.

RobW’s picture

In 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.

caschbre’s picture

That'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.

ParisLiakos’s picture

knalstaaf’s picture

When 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

joelcollinsdc’s picture

I'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.

aaron’s picture

Status: Needs review » Needs work

The last submitted patch, file_entity-override_image_style.patch, failed testing.

Devin Carlson’s picture

Status: Needs work » Closed (works as designed)
Pere Orga’s picture

Issue summary: View changes
Status: Closed (works as designed) » Active

I 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.