Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When entity properties are retrieved with entity_get_property_info()
from the Entity API module, fields properties are returned as entity properties. But translatable properties are not translated as the Entity API itself has no knownledge of the Field translation module.
Proposed resolution
Hook into the Entity properties API to provide translations of field properties.
Comments
Comment #1
pbuyle CreditAttribution: pbuyle commentedComment #2
pbuyle CreditAttribution: pbuyle commentedThe attached patch implement the suggested solution.
Comment #3
pbuyle CreditAttribution: pbuyle commentedComment #4
AnybodyI can confirm this problem still exists. For me the proposed solution works good, but we need further feedback!
Comment #5
joseph.olstaddue to testbot change this patch needs another test.
reroll of original patch 2 , same patch as #2 but new name.
Comment #7
joseph.olstadFixed in dev 7.x-1.x , let this simmer for a while in dev.
Comment #8
das-peter CreditAttribution: das-peter at Cando commentedAfter updating to the latest dev I've got a recursion loop that's caused by this adjustment.
Scenario:
Cold cache.
hook_menu
commerce_flat_rate_menu()
is invoked.commerce_flat_rate_commerce_shipping_service_info()
, which callsi18n_object('commerce_flat_rate', $service)->translate($language->language);
i18n_object_info()
which builds the cache.i18n_object_info()
invokes$info = module_invoke_all('i18n_object_info');
entity_i18n_object_info()
RulesI18nStringController::hook_object_info()
which bases onEntityDefaultI18nStringController
EntityDefaultI18nStringController::translatableProperties()
is called.entity_get_all_property_info()
which bases onentity_get_property_info()
hook_entity_property_info
is triggered.entity_entity_property_info()
which callsentity_metadata_field_entity_property_info()
i18n_field_entity_property_callback()
is called.i18n_field_translate_property()
this relies oni18n_string_object_translate()
i18n_string_object_translate()
relies oni18n_object()
aaand we're just rebuilding it's cache and without cache it's rebuilding the cache... means restart at 4.I'm not yet sure how to proceed yet as I don't spot an obvious issue in the implementations - just a an unfortunate combination of dependencies. However, given the recent change introduced this issue I'm afraid that we've to solve it too.
Comment #9
joseph.olstad@das-peter thanks for the thorough analysis, one question, so does backing off commit at #6 avoid the recursion loop?
Comment #10
das-peter CreditAttribution: das-peter at Cando commented@joseph.olstad Took me a moment but I think I was able to come up with some sort of solution ;) If the
i18n_object_info
cache isn't present we skip the processing but rebuildentity_get_property_info
in our implementation ofhook_i18n_object_info_alter()
. By usingi18n_field_module_implements_alter()
we ensure our implementation ofhook_i18n_object_info_alter()
is the last that runs. This means we should have the full data fori18n_object_info
- even if not, at least we wont end up causing a endless recursion.The attached patch also adds a watchdog logging in case
i18n_object_info
still isn't available . might help us to identify some other edge cases.The solution will have a small window in which untranslated property info are cached / used - but this approach was the best I could think of.
Comment #12
joseph.olstad@das-peter figured we should commit this immediately into dev
stalling a release until dev gets more bake time.
Comment #13
AnybodyWhao great, thank you very much!
Comment #14
das-peter CreditAttribution: das-peter at Cando commented@joseph.olstad Thanks for committing I didn't that right away since I wanted another pair of eyes checking out what I came up with ;) But I agree with the fast commit!
Now let's see if someone hit's the new watchdog message ;)