I have a EntityReferenceItemList

  $list = {
    'list' = [],
    'langcode' = 'en'
  }

If i try to get entities from this list:

  foreact ($list as $delta => $item) {
   $entity = $item->entity;
  }

I get entity in default language not in ItemList language. How to get entity with language setted in ItemList?

Comments

divined created an issue. See original summary.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

amateescu’s picture

Category: Bug report » Support request
Status: Active » Fixed

You can simply call getTranslation() on $item->entity. Something like this:

foreach ($list as $delta => $item) {
  $entity = $item->entity->getTranslation($langcode]);
}

Status: Fixed » Closed (fixed)

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