Maps from an entity object to the storage record of the data table.
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
$langcode: The language code of the translation to get.
\stdClass The record to store.
protected function mapToDataStorageRecord(EntityInterface $entity, $langcode) {
$default_langcode = $entity
->language()->langcode;
// Don't use strict mode, this way there's no need to do checks here, as
// non-translatable properties are replicated for each language.
$translation = $entity
->getTranslation($langcode, FALSE);
$definitions = $translation
->getPropertyDefinitions();
$schema = drupal_get_schema($this->entityInfo['data_table']);
$record = new \stdClass();
foreach (drupal_schema_fields_sql($this->entityInfo['data_table']) as $name) {
$info = $schema['fields'][$name];
$value = isset($definitions[$name]) && isset($translation->{$name}->value) ? $translation->{$name}->value : NULL;
$record->{$name} = drupal_schema_get_field_value($info, $value);
}
$record->langcode = $langcode;
$record->default_langcode = intval($default_langcode == $langcode);
return $record;
}