protected function EntityTranslationDefaultHandler::doSaveTranslations in Entity Translation 7
Saves entity translation records to the storage.
1 call to EntityTranslationDefaultHandler::doSaveTranslations()
File
- includes/
translation.handler.inc, line 613 - Default translation handler for the translation module.
Class
- EntityTranslationDefaultHandler
- Class implementing the default entity translation behaviours.
Code
protected function doSaveTranslations($translations, $table, $revision = FALSE) {
// Delete and insert, rather than update, in case a value was added.
$query = db_delete($table)
->condition('entity_type', $this->entityType)
->condition('entity_id', $this->entityId);
// If we are storing translations for the current revision or we are
// deleting the entity we should remove all translation data.
$langcode = $translations->original;
$hook = isset($translations->hook) ? $translations->hook : array();
if ($revision && $this
->isRevisionable() && (empty($hook[$langcode]['hook']) || $hook[$langcode]['hook'] != 'delete')) {
$query
->condition('revision_id', $this->revisionId);
}
$query
->execute();
if (count($translations->data)) {
$columns = array(
'entity_type',
'entity_id',
'revision_id',
'language',
'source',
'uid',
'status',
'translate',
'created',
'changed',
);
$query = db_insert($table)
->fields($columns);
// These values should override the translation ones as they are not
// supposed to change.
$overrides = array(
'entity_type' => $this->entityType,
'entity_id' => $this->entityId,
'revision_id' => $this
->isRevisionable() ? $this->revisionId : $this->entityId,
);
// These instead are just defaults.
$defaults = array(
'source' => '',
'uid' => $GLOBALS['user']->uid,
'translate' => 0,
'status' => 0,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
);
foreach ($translations->data as $translation) {
$translation = $overrides + $translation + $defaults;
$query
->values($translation);
}
$query
->execute();
}
}