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.
The function entity_metadata_field_get_language returns the entity language instead of the field language. There is probably a good reason for that, but I can't figure out why. So here is a patch that first looks for the field language then falls back on the entity language.
Comment | File | Size | Author |
---|---|---|---|
field-language-instead-of-entity-language.patch | 1.56 KB | StoraH | |
Comments
Comment #1
StoraH CreditAttribution: StoraH commentedComment #2
emattias CreditAttribution: emattias commentedComment #3
joelpittetThanks you for the patch @StoraH, this fixed my issue that looked like #2342991: Get the translated product reference field to display the products with the correct language. for commerce product reference field translation.
Comment #4
logaritmisk CreditAttribution: logaritmisk commentedIf I understand correctly, this is because if we want to read/write to the fields, we want to use the language the entity uses, for example.
But if you want to display the values for the user, you will have to set the language to use.
It's annoying. I love entity_metadata_wrapper and I use it, like, everywhere and Slate heavily depends on it, but I can understand why it works like it do. Do get a round this, you would have to implement another method to use to display the value for a field.
Maybe something like
$wrapper->field_body->display();
Comment #5
fagoThat's the reason - field_language() has language fallback for display, but we are in a general read/write operation.