I am struggling with a misbehaviour of the file entity module (supposedly). If I change the language with the language switcher alt and title texts stay on the language that was active at the last cache flush or the resaving of the node. Is it some kind of cacheing issue?
IF I change the format of the image field to 'rendered file' on the content display settings page everything seems to be working fine, alt tags and titles show up properly. However most sites use image styles, other formatters like flex slider, colorbox etc, therefore it is an important functionality.
I could reproduce the problem on sympletest.me and on my test environment as well.
I use the latest media module, file entity and entity translation modules.
1. Core and Basic module installation on one language
3. Enabled 1 more language
2. File Entity configuration -> in TRANSLATABLE ENTITY TYPES image is configured with the following options:
- Hide language selector
- Exclude Language neutral from the available languages
- Prevent language from being changed once the entity has been created
4. Created custom content type for testing
- Content type is translatable with entity translation
- Added image field with media file selector widget not translatable (unlimited values)
- Configured display settings of the image field format to 'image'.
3. Uploaded single or multiple image files through content/files/add files or via media widget, does not make a difference
4. After upload I translated Alt and title fields on multiple images through content/files/edit/translate
5. Added images to the content's image field through media browser
6. After saving and/or cache flushing, my alt and title tags stays on the language (regardless of the chosen language) that was active.
I created more related issues on this while I was trying to investigate. Thanks David_Rothstein for giving a clue quoted here:
This does seem like it could be a caching issue. If I understand the code flow correctly, the File Entity module is setting the alt and title when the field is loaded, but from https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/fun... you can see that the loaded field data gets cached.
Possibly File Entity shouldn't be setting such dynamic properties in this hook (or at least not only setting them in this hook; it could set them again later I suppose in code that doesn't get cached)...
Comment | File | Size | Author |
---|---|---|---|
#14 | file-entity-alt-title-language-2665960-14.patch | 3.26 KB | David_Rothstein |
|
Comments
Comment #2
hefterbrumi CreditAttribution: hefterbrumi commentedComment #3
hefterbrumi CreditAttribution: hefterbrumi commentedComment #4
hefterbrumi CreditAttribution: hefterbrumi commentedUnfortunately I still can't resolve this. Anybody else has this bug?
Comment #5
Yazzbe CreditAttribution: Yazzbe commentedI have the same problem with entity translation and bxslider / colorbox.
A cache flush makes the correct alt/title translation visible for a specific language.
Changing the language, requires again a cache flush to see the proper translation.
caching issue ?
Comment #6
joseph.olstadI confirm same issue is occuring here. Only 'rendered file' is able to provide the correct field language for alt text and title text of the file/image.
Comment #7
joseph.olstadI've spent some time looking into the above comments but didn't come up with anything yet.
Not sure if the issue below will provide any additional insight.
#2017647: Media browser translatable alt and title fields for translatable parent entity
Comment #8
joseph.olstadMy use-case is views.
I made one useful discovery:
function file_entity_field_formatter_view is not called when 'image' formatter is selected, however it IS called when Rendered file is chosen on the field configuration for the view.
So, if image has any formatter_view it might be handled by perhaps another implementation of formatter_view but not the one in the file_entity module.
**EDIT**
found another formatter_view hook that suspect provides 'image'
media/mediafield/mediafield.module
also possibly
includes/media.fields.inc
....to be continued
Comment #9
joseph.olstad**EDIT** see core patch here that fixes this forever: #2835135: image formatter needs to handle alt/title from file entities on images for multi language support
The D8 issue #2735111: Decide how to handle alt/title on images when core formatter is used seems to me to explain the problem, it appears that D8 has the exact same problem
and if that issue gets resolved we can probably backport it to D7 unless of course we fix this in D7 first and then port the fix to D8. Either way, my current focus is fixing this in D7.See the patchNOTE: as a workaround, if you still want image styles when using 'Rendered File' (because Rendered File provides the alt and title in the correct language) you can create a tpl file for the field and do something similar as follows:
Comment #10
joseph.olstadSo, if I understand correctly the issue #2735111 it looks like we'll have to fix this by writing a D7 core patch because the core formatter for image is not correctly using file_entity .
Comment #11
joseph.olstadI just finished writing a small core patch for D7 fixes this issue. Patch to follow shortly.
Comment #12
joseph.olstadsee patch for the core image module that fixes this in D7 #2835135: image formatter needs to handle alt/title from file entities on images for multi language support
Comment #13
joseph.olstadThis is still an issue, the core patch I wrote does fix the problem,
[#11824241-1]
but it would be nice if we didn't have to patch core , would be nice to resolve this in file_entity instead of core.
Comment #14
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedHere's a patch that tries what I suggested in the long-ago quote mentioned in the issue summary. It's kind of ugly, but it seems to work, and it doesn't depend on a particular image formatter being used (unlike the core patch).
I tested this with a regular image attached to a node which was displayed using the Image module formatter, an image attached to a field collection on a node which was displayed using the Image module formatter, and an image attached to a node which was displayed using the Colorbox module's formatter. I also tested with and without the Entity Cache module. Seemed to work correctly in all cases. Definitely needs review and testing by others though.
Comment #15
joseph.olstad@david_rothstein, thank you so much for that patch. I backed off the core patch, cleared caches, applied your patch and tested, looks great !!!
Comment #16
joseph.olstadComment #19
joseph.olstadComment #20
joseph.olstadFYI, someone has reported an issue that might be a regression but not sure I haven't noticed anything myself yet and I haven't yet taken the time to really understand what this other issue is.
they've supplied a patch, haven't yet reviewed.
#2918049: Image field alt and title text overridden by file_entity_alt and file_entity_title
Comment #22
joseph.olstadFYI:
there is a related performance enhancement /fix that touches the code that was committed in this issue.
#2966026-2: Performance fix - rename file_entitycache_file_load to file_entity_entitycache_file_load
Appreciate a review of the new patch
see
#2966026-2: Performance fix - rename file_entitycache_file_load to file_entity_entitycache_file_load
and I also (with FabianX's guidance) rolled a somewhat related performance patch here too:
#2642764-34: Speed up via shortcutting token file_entity_file_load
Comment #23
joseph.olstad