public static function EntityTranslationDefaultHandler::loadMultiple in Entity Translation 7
Read the translation data from the storage.
2 calls to EntityTranslationDefaultHandler::loadMultiple()
File
- includes/
translation.handler.inc, line 458 - Default translation handler for the translation module.
Class
- EntityTranslationDefaultHandler
- Class implementing the default entity translation behaviours.
Code
public static function loadMultiple($entity_type, $entities) {
$entity_info = entity_get_info($entity_type);
if (isset($entity_info['entity keys']['translations'])) {
$translations_key = $entity_info['entity keys']['translations'];
}
else {
// If no translations key is defined we cannot proceed.
return;
}
$revisionable = self::isEntityTypeRevisionable($entity_type);
$revisions_ids = array();
foreach ($entities as $id => $entity) {
$entities[$id]->{$translations_key} = self::emptyTranslations();
if ($revisionable) {
list(, $revisions_id, ) = entity_extract_ids($entity_type, $entity);
$revisions_ids[$id] = $revisions_id;
}
}
$table = $revisionable ? 'entity_translation_revision' : 'entity_translation';
$query = db_select($table, 'et')
->fields('et')
->condition('entity_type', $entity_type);
if (!$revisionable) {
$query
->condition('entity_id', array_keys($entities), 'IN');
}
else {
$query
->condition('revision_id', $revisions_ids, 'IN');
}
$results = $query
->execute();
foreach ($results as $row) {
$id = $row->entity_id;
$entities[$id]->{$translations_key}->data[$row->language] = (array) $row;
// Only the original translation has an empty source.
if (empty($row->source)) {
$entities[$id]->{$translations_key}->original = $row->language;
}
}
}