I've been pulling my hair out on this one for weeks, but I've finally figured it out.

Setup:

Using auto_entitylabel on a multilingual site which uses translated name values of taxonomy terms in the generated paths via pathauto. Saving a node sometimes results in generated paths with the term names translated in the incorrect languages. This is because during auto_entitylabel_set_title(), the multilingual titles are generated by token_replace() and entity_token_tokens(), an implementation of hook_token() hooks into this and creates metadata wrapper objects around relevant entities, caching objects in the process.

Placing the following code immediately after the multilingual title generation (around line 211 in entity_autolabel.module) fixes the problem, but also adds a significant amount of overhead as we are purging all static entity caches. If someone knows a better, more targeted method, I would suggest using that. In the meantime, I hope this can help another developer from going bald.


      //Clear entity static caches, which now have been corrupted with translated versions of entities from above.
      $entiy_info = entity_get_info();
      $entity_types = array_keys($entiy_info);
      foreach ($entity_types as $entity_type) {
        $entity_controller = entity_get_controller($entity_type);
        $entity_controller->resetCache();
      }

Comments

bburg’s picture

Title: Multilingual Auto Label Corrupts Entity Controller Caches » Multilingual Auto Label Corrupts Entity Static Caches
bburg’s picture

Issue summary: View changes
bburg’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
879 bytes

Patch with above code.

bforchhammer’s picture

Oh wow, that sounds like a difficult one to figure out. Thanks for sharing!

Is it necessary to clear the cache for all entity types? I would imagine that you should be able to simply call entity_get_controller($type)->resetCache() to only clear the cache for the current one.

I'm also wondering whether it would also work to simply switch back to the original entity language; that should also clear the cache, but would be limited to the entity being edited and therefore might have less of a performance impact.

bburg’s picture

The patch in #3 is definitely the sledgehammer quick-fix. I would recommend a more targeted approach if possible, perhaps saving the current language title generation until the end, which in theory would write over the cached items in other languages?

bburg’s picture

Status: Needs review » Needs work