function lingotek_entity_translation_save_status in Lingotek Translation 7.5
Same name and namespace in other branches
- 7.7 lingotek.util.inc \lingotek_entity_translation_save_status()
- 7.4 lingotek.util.inc \lingotek_entity_translation_save_status()
- 7.6 lingotek.util.inc \lingotek_entity_translation_save_status()
Save a translation to the Entity Translation table with status and additional parameters
4 calls to lingotek_entity_translation_save_status()
- lingotek_cleanup_notify_entity_translation in ./
lingotek.util.inc - Report all Lingotek translations to the Entity Translation module
- lingotek_entity_download in ./
lingotek.module - lingotek_publish_form_submit in ./
lingotek.page.inc - Submit handler for the lingotek_publish_form form. Update the entity_translation module publishing fields
- lingotek_update_7408 in ./
lingotek.install - Creates an upgrade path for existing translated content to be inserted into entity_translation module table if necessary
File
- ./
lingotek.util.inc, line 1204 - Utility functions.
Code
function lingotek_entity_translation_save_status($entity_type, $entity, $language_codes, $addtl_params = NULL) {
global $user;
$languages_updated = array();
$updates = 0;
if (!entity_translation_enabled($entity_type)) {
return array(
$languages_updated,
$updates,
);
}
if ($entity_type == 'node' && !entity_translation_node_supported_type($entity->type)) {
return array(
$languages_updated,
$updates,
);
}
$handler = entity_translation_get_handler($entity_type, $entity);
$source_langcode = lingotek_entity_langcode($entity_type, $entity);
$translations = $handler
->getTranslations();
if (empty($translations->original)) {
$handler
->initTranslations();
$handler
->saveTranslations();
}
foreach ($language_codes as $langcode) {
if ($langcode !== 0) {
$et_params = array(
'language' => $langcode,
'translate' => isset($entity->translate) ? $entity->translate : 0,
'uid' => !empty($entity->uid) ? $entity->uid : $user->uid,
'changed' => !empty($addtl_params['changed']) ? $addtl_params['changed'] : time(),
);
if (!empty($addtl_params['created'])) {
$et_params['created'] = $addtl_params['created'];
}
if ($langcode != $source_langcode) {
$et_params['source'] = $source_langcode;
}
if (isset($addtl_params['status_request'])) {
$et_params['status'] = $addtl_params['status_request'];
}
else {
// Check for a current status for the given langcode.
if (isset($entity->translations->data[$langcode]['status'])) {
$et_params['status'] = $entity->translations->data[$langcode]['status'];
}
elseif (isset($entity->translations->data[$entity->language])) {
$et_params['status'] = $entity->translations->data[$entity->language]['status'];
}
else {
// Set to published as a default.
$et_params['status'] = 1;
// published
}
}
$handler
->setTranslation($et_params);
$languages_updated[$langcode] = lingotek_language_name($langcode);
$updates++;
}
}
$handler
->saveTranslations();
return array(
$languages_updated,
$updates,
);
}