When I implement this hook, I end up with 'en', when everywhere else it's 'und'

It seems like the problem is coming from line 1252 in field_collection.module, the FieldCollectionItemEntity/Entity's view function is being invoked without passing on the $langcode as an argument.

If I change:
$element[$delta]['entity'] = $field_collection->view($view_mode);

to:

$element[$delta]['entity'] = $field_collection->view($view_mode, $langcode);

It fixed my issue, although I don't know if this behavior is on purpose, and whether this change has further implications...

Thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

-enzo-’s picture

Issue summary: View changes

I found the same issue the funciton view of Class FieldCollectionItemEntity don't detect the current language if isn't set, as you can see in the following code

  public function view($view_mode = 'full', $langcode = NULL, $page = NULL) {
    // Ensure file fields on the entity have their URI loaded for previews.
    if ($langcode == NULL) {
      $langcode = LANGUAGE_NONE;
    }
BramDriesen’s picture

This issue still persist in the latest beta, I suggest patching the $langcode param.

BramDriesen’s picture

Assigned: Unassigned » BramDriesen
Status: Active » Needs review
FileSize
1.38 KB

Patch attached and ready for review.

Status: Needs review » Needs work

The last submitted patch, 3: implementing-2042015-3.patch, failed testing.

BramDriesen’s picture

Status: Needs work » Needs review
FileSize
1.38 KB

I re-created the patch since I did the diff from the master branch instead of the other way around.

BramDriesen’s picture

Assigned: BramDriesen » Unassigned

jmuzz’s picture

Status: Needs review » Fixed

Thanks for the patch @BramDriesen.

I think this was an accidental omission.

Status: Fixed » Closed (fixed)

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

minorOffense’s picture

This commit actually breaks language detection in some cases. Looks like $langcode has the wrong value so Drupal isn't auto detecting language anymore. It's always using the default value.

Not sure if this is an issue for field collections but this definitely breaks language detection on a client site of ours.

Daniel Korte’s picture

I agree with @minorOffense. This patch breaks language detection in field collections for me as well.

BramDriesen’s picture

@Daniel Korte Create a new issue linked to this one. Commenting on a closed issue won't get it fixed :)

Daniel Korte’s picture