Creates the entity to be translated.
array $values: An array of initial values for the entity.
string $langcode: The initial language code of the entity.
string $bundle_name: (optional) The entity bundle, if the entity uses bundles. Defaults to NULL. If left NULL, $this->bundle will be used.
The entity id.
protected function createEntity($values, $langcode, $bundle_name = NULL) {
$entity_values = $values;
$entity_values['langcode'] = $langcode;
$info = entity_get_info($this->entityType);
if (!empty($info['entity_keys']['bundle'])) {
$entity_values[$info['entity_keys']['bundle']] = $bundle_name ?: $this->bundle;
}
$controller = entity_get_controller($this->entityType);
if (!$controller instanceof DatabaseStorageControllerNG) {
foreach ($values as $property => $value) {
if (is_array($value)) {
$entity_values[$property] = array(
$langcode => $value,
);
}
}
}
$entity = entity_create($this->entityType, $entity_values);
$entity
->save();
return $entity
->id();
}