Problem/Motivation

Currently the handling of the alt / title properties of file entities in file_entity_file_load() doesn't take in account that there's also the Entity cache module which caches entities language agnostic.
Now if you fix the File Entity module with #2553067: Language option missing for token replacements to make the alt / title property replacement language aware (probably using Entity Translation) then using Entity cache will basically revert the fix by serving the cache, language agnostic, version.
So the alt / title properties will be stuck in whatever language was used to prime the Entity cache.

Proposed resolution

Use hook_entitycache_ENTITY_TYPE_load() to re-run the alt / title property replacement in the current language whenever the entities are served by Entity cache.
To do so split the current replacement into a dedicated function (how about file_entity_set_title_alt_properties()?) so it can be re-used in both hooks.

The attached patch does exactly this.
It also implements parts of the change here: #2553067: Language option missing for token replacements

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

das-peter created an issue. See original summary.

das-peter’s picture

Title: Inconcistency when using entitycache and entity_translation » Inconsistency when using entitycache and entity_translation
purushotam.rai’s picture

This works for me. Thanks

joseph.olstad’s picture

I also noticed this issue. See the approach I took (a small, fairely straightforward core patch)
#2835135: image formatter needs to handle alt/title from file entities on images for multi language support

I'm thinking of committing either the patch to file_entity by @David_Rothstein
#2473621: Alt and title text don't appear in the correct language when viewing a file in a language other than the current page language

OR
the one by @das-peter :
#2806081: translated Title and Alt text fix, use optionally with entitycache and entity_translation

different approaches , but both look good. I'm leaning towards the @David_Rothstein approach because it is maybe slightly simpler? not sure.

However, I haven't >yet< tested either of the last two approaches as we're still using the core patch I wrote.

joseph.olstad’s picture

purushotam.rai’s picture

@joseph.olstad, for me also the patch gave positive results:
https://www.drupal.org/files/issues/file_entity-integrate-with-entity-ca...

Thanks

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

It's going in

  • das-peter authored 5be67c8 on 7.x-2.x
    Issue #2806081 by das-peter, David_Rothstein, joseph.olstad, purushotam....
joseph.olstad’s picture

joseph.olstad’s picture

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

  • das-peter authored 5be67c8 on 7.x-3.x
    Issue #2806081 by das-peter, David_Rothstein, joseph.olstad, purushotam....
joseph.olstad’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev
Status: Reviewed & tested by the community » Fixed
joseph.olstad’s picture

Title: Inconsistency when using entitycache and entity_translation » translated Title and Alt text fix, use optionally with entitycache and entity_translation

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.