Problem/Motivation
As it stands now it seems to me that the available "Thumbnail" formatter is not designed* to display the latest image and its metadata: it does not update changes to an existing image entity. Rendering it useless for content display.
This is leading to widespread confusion, I think at least these issues are related to this:
- #2749695: Thumbnail not updated
- #2849522: Updating media doesn't actually update media
- #2772045: Update modified metadata in mapped fields
- #2844028: Change 'Thumbnail' Image Formatter to 'Image Style'
* What the "Thumbnail" formatter is designed for is not the scope of this issue.
Proposed resolution
I believe a media_entity_image specific formatter should be available to provide output of the current image conforming a selected image style with correct and current alt + title attributes.
Remaining tasks
Discussion & testing
Note:
To use the patch, switch your field to "Media image" at "Manage display" of your node type: /admin/structure/types/manage/YOURNODETYPE/display and clear caches.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | add_image_formatter-2850169.patch | 6.55 KB | rmpereira |
| #44 | interdiff_5-41.txt | 697 bytes | chop |
| #41 | add_image_formatter-2850169-41.patch | 6.35 KB | liberatr |
| #34 | manage_image.png | 90.9 KB | kbasarab |
| #23 | Screen Shot 2017-02-20 at 15.34.11.png | 59.13 KB | keesje |
Comments
Comment #2
keesje commentedComment #3
kevinquillen commentedPatch is empty
Comment #4
keesje commentedoops, dunno what went wrong there
Comment #5
gro commentedTested and working. Just a couple of small coding standards and debug fixes @keesje
PHPDoc missing for param EntityStorageInterface $image_style_storage
Remove debug.
Comment #6
keesje commentedFixed that, thanks.
Comment #7
keesje commentedComment #8
sabda.wiguna commentedsame issue here, applied the patch but still not working.
Comment #9
keesje commented@sabda.wiguna, you have to switch to the new formatter. Dont use "Thumbnail" but "Media image". Did you do that?
Comment #10
sabda.wiguna commentedAhh, sorry, I just updated it and it's working on media list (views), but not on node display with field image.I still see the old image. How to get the latest image?
Comment #11
keesje commentedProbably the same ;-) switch that field to "Media image" at "Manage display" of your node type: /admin/structure/types/manage/YOURNODETYPE/display
and clear caches
Comment #12
sabda.wiguna commentedI didn't get that format('Media Image') https://www.screencast.com/t/ZzfTIhINzbU . It's weird.
Comment #13
keesje commentedfield type is "entity reference" with reference type "media" and reference type bundle "image"?
Comment #14
sabda.wiguna commentedI have video embed only as media reference https://www.screencast.com/t/u6vaY3do . Media entity image is enabled already.
Comment #15
keesje commentedComment #16
slashrsm commentedThis patch basically does what Field formatter module is already dosing. Please check that.
Comment #17
demonde commentedIs there a way to use alt and title attributes from media image fields?
Comment #18
keesje commented@Janez, I played around with field_formatter (oh, documentation link is dead). I dont see how it adds value to simply displaying images using imagestyles from an entity scope? I can use it, but I still need to add a media_image display per needed imagestyle. These display's I can use without field_formatter.
Does field_formatter implement a simple, direct formatter for media_image fields to select an imagestyle and show the image? That's whtat missing IMO.
Comment #19
keesje commented@demonde thats one issue I try to address here. Please try the patch and share your findings.
Comment #20
slashrsm commented@keesje: "Field formatter with inline settings" does exactly that - it allows you to select a field on the referenced entity and display it using an arbitrary formatter. No need to create view modes.
Comment #21
keesje commentedComment #22
slashrsm commentedAlso updated the documentation link on Field formatter project page.
Comment #23
keesje commentedhm, I used the stable release. Might be my codebase, I did exactly what you describe on an existing field, but got "Thousands marker" as next option, see screenshot. But playing some more, selecting another option, saving, reopening, reselecting "Image" formatter I see proper image styles.
I see your point, this could work allright. Still puzzled if media_entity_image shouldnt provide its own formatter. Now people seem to use "Thumbnail" for displaying content images in the wild.
Comment #24
slashrsm commentedThis looks like a bug in the formatter configuration form. Out of scope for this issue. We should move the debate in the other issue queue.
Comment #25
keesje commentedAgreed. discussion if media_entity_image benefits from its own formatter looks appropriate here to me. I think it should and care about your opinion?
Comment #26
slashrsm commentedMy general opinion is that if we can solve problems in a generalized way then we should definitely strive to do so. By doing that more people benefit from the work, we end up with less redundancy and higher possibility for more community contributions.
It is also worth considering that when/if media entity lands in core (hopefully 8.4) this module will become deprecated as it will be included too. Parts that won't be included will probably need to find a new home.
Comment #27
keesje commentedOk, I dig that, especially from a techical POV. If this patch isnt appropriate, then imo somehow it should be made very clear that:
"Thumbnail" formatter is not meant for content usage, but entity displays should be used, or field_formatter the way you showed me.
Comment #28
slashrsm commentedAgreed. https://github.com/drupal-media/d8-guide would be a great place to add that.
Comment #29
demonde commented@keesje: I cannot see an option to determine alt + title by this formatter.
IMO a media entity image formatter is really helpful, if it enables me to choose values such as alt, title and caption from any plain text field of the media image entity.
Another (maybe better) way would be a media image formatter that prints out the media entity as rendered entity but overwrites / determines the image style.
Comment #30
keesje commented@demonde, this patch does not provide that. You could try @slashrsm's suggested field_formatter module, this patch is probably not goin in.
Comment #31
demonde commentedWell there is a common use case:
I have a media entity image with the fields:
I want to output image with description as title and alt attribute and below the image as caption description and creator.
I think there is no way to do so right now, also not with field formatter.
In Dr7 there was a module such as "imagefield tokens" as a workaround. The media module in dr7 would create its own alt + title field on the image entity level.
Therefore there is a open conceptional issue how to output media image entities in dr8.
Or is there another way to accomplish this?
Comment #32
keesje commentedcant help you, maybe open a new support issue or forum topic?
Comment #33
demonde commentedThanks for notice. So there is the alternative to use views field formatter or custom formatters.
Comment #34
kbasarab commentedConfirmed this is working as expected in the following setup:
One note is that the mapping of the fields does not happen on the formatter but rather what was already saved in the media bundle configuration.
Tested against 1.2 stable release. Patch applies via composer.
Comment #35
Mike Dodd commentedTested against 1.2 stable release. Patch applies via composer and works great. Thank you.
Comment #36
jds1Thank you for this patch. It seems to work fine but I am not getting an option for alt text when I select the "Media Image" field formatter. I've looked in several places and am just not seeing it. I've seen alt text as a default option for file entities but not media bundles. Has anyone found a solution for alt text to be added on upload via an entity browser?
Comment #37
demonde commentedSince media entity and media entity image is now in core, it might be an issue to implement this feature to the core module?
Comment #38
jds1Hi @demonde. Good suggestion. I've created https://www.drupal.org/project/drupal/issues/2924391. Any future convo can be had over there. This issue is resolved as far as I'm concerned. Thank you!
Comment #39
demonde commentedThis solves my issue #31 exactly as I proposed:
https://www.drupal.org/project/drupal/issues/1291262#comment-12302748
Comment #40
liberatrThis update adds one line to sort the names of the image formatters in the dropdown.
On the core screen the formatters are sorted this way. /admin/config/media/image-styles
Comment #41
liberatrUploaded the wrong patch. Fixes #40.
Comment #42
jds1So, there's now a way to get alt text for an image via Inline Entity Form, but the "Thumbnail" plugin of courses uses "Thumbnail" as the alt text. It is also not the appropriate plugin to use for "latest image." Has there been any progress on a Drupal 8 version of this, as mentioned in #37? I looked around and haven't seen anything, so I thought I'd start here.
Comment #43
anybodyI agree Field formatter with inline settings is the most universal solution and a custom solution should not be required.
Instead it should be used and filled with default settings.
Somehow the current "Preview" formatter which isn't being updated when the image is changed doen't make any sense to me.
Comment #44
chop commentedFor those who were wondering (like me) what changed between patch 5 and patch 41, I am attaching the interdiff here.
Comment #45
rmpereira commented#40, the sort() function broke the keys of "$element['image_style']['#options']" and the usage of image style doesn't work.
I update the patch with the function asort() instead.
Comment #47
randell commented+1 for Field Formatter making it work.
Comment #48
rakesh.gectcrI had the same problem with, I ended up creating new image formatter to solve the problem this is the module https://www.drupal.org/project/responsive_media_image, hope this helps.