Commit 34dec4b7 authored by catch's avatar catch

Issue #2078625 by yched: Field/FieldItem value objects should carry their language.

parent 5b578a55
......@@ -315,7 +315,9 @@ protected function getTranslatedField($property_name, $langcode) {
$value = $this->values[$property_name][$default_langcode];
}
}
$this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
$field = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
$field->setLangcode($langcode);
$this->fields[$property_name][$langcode] = $field;
}
}
return $this->fields[$property_name][$langcode];
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\ItemList;
use Drupal\Core\Language\Language;
/**
* Represents an entity field; that is, a list of field item objects.
......@@ -36,6 +37,13 @@ class Field extends ItemList implements FieldInterface {
*/
protected $list = array();
/**
* The langcode of the field values held in the object.
*
* @var string
*/
protected $langcode = Language::LANGCODE_DEFAULT;
/**
* Overrides TypedData::__construct().
*/
......@@ -48,6 +56,20 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface
$this->list[0] = $this->createItem(0);
}
/**
* {@inheritdoc}
*/
public function setLangcode($langcode) {
$this->langcode = $langcode;
}
/**
* {@inheritdoc}
*/
public function getLangcode() {
return $this->langcode;
}
/**
* {@inheritdoc}
*/
......
......@@ -27,6 +27,22 @@
*/
interface FieldInterface extends ListInterface, AccessibleInterface {
/**
* Sets the langcode of the field values held in the object.
*
* @param string $langcode
* The langcode.
*/
public function setLangcode($langcode);
/**
* Gets the langcode of the field values held in the object.
*
* @return $langcode
* The langcode.
*/
public function getLangcode();
/**
* Gets the field definition.
*
......
......@@ -36,6 +36,13 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface
}
}
/**
* {@inheritdoc}
*/
public function getLangcode() {
return $this->parent->getLangcode();
}
/**
* {@inheritdoc}
*/
......
......@@ -23,6 +23,14 @@
*/
interface FieldItemInterface extends ComplexDataInterface {
/**
* Gets the langcode of the field values held in the object.
*
* @return $langcode
* The langcode.
*/
public function getLangcode();
/**
* Gets the field definition.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment