SearchApiEtDatasourceController::setLanguage() is supposed to recursively set languages on wrapper fields. Most of the function code determines nested fields, and this line sets the language:

          $wrapper->$field->language($langcode);

This does not work for entity reference fields since the language should be set not only on the particular field, but on the parent wrapper too.

Currently, as language is not set on the referenced entity, its wrapper is initialized with the default "und" language, and field values are retrieved according to the current global language.

Comments

Leksat created an issue. See original summary.

leksat’s picture

Status: Active » Needs review
StatusFileSize
new703 bytes

Attached patch fixes the issue for me.

leksat’s picture

Issue summary: View changes
thepanz’s picture

Hi Leksat, do you have an example for that?
I am indexing an entity A, and from a referenced entity B, the B.title_field
I am able to get the correct title_field indexed without your patch.
Is this a 'too simple' to test?

Furthermore: could issue #2335885: 'langcode' option in info array is not applied be related?

thepanz’s picture

Status: Needs review » Postponed (maintainer needs more info)
fmfpereira’s picture

Hi i'm having the same issue.

On my scenario we are indexing a text field from an entity referenced entity.

We are using entity translation and the entity reference field is not translated (to allow entity translation display based on current language).

In summary this mean that the parent entity language must be used for the referenced entity.

I've rewritten the patch #2 according module codding standard and against last branch dev version.

fmfpereira’s picture

Status: Postponed (maintainer needs more info) » Needs review
berdir’s picture

Also had this problem, additionally, in my case it was multi-value fields, and the list wrapper doesn't have a language() method, so I added an extra check for that. Maybe there would be a better way to do this, don't know the entity wrapper in 7.x very well.