function lingotek_node_save in Lingotek Translation 7.4
1 call to lingotek_node_save()
- lingotek_node_update in ./
lingotek.module - Implements hook_node_update().
File
- ./
lingotek.module, line 955
Code
function lingotek_node_save($node) {
if (!isset($node->lingotek)) {
// load default lingotek settings when alternate node creation paths are employed (e.g., commons)
lingotek_node_load(array(
$node,
), array());
}
$has_not_been_uploaded = !isset($node->lingotek['document_id']) || empty($node->lingotek['document_id']);
$disabled_selected = $node->lingotek['profile'] == LingotekSync::PROFILE_DISABLED;
$disabled = isset($node->lingotek['node_sync_status']) && $node->lingotek['node_sync_status'] == LingotekSync::STATUS_DISABLED;
if ($disabled_selected && !$disabled) {
LingotekSync::setNodeEnabled($node->nid, FALSE);
}
elseif (!$disabled_selected && $disabled) {
LingotekSync::setNodeEnabled($node->nid, TRUE);
}
$remove = lingotek_get_profile_fields($has_not_been_uploaded, TRUE);
$remove[] = 'profile';
db_delete('lingotek')
->condition('nid', $node->nid)
->condition('lingokey', $remove, 'IN')
->execute();
if ($node->lingotek['profile'] == LingotekSync::PROFILE_CUSTOM) {
$ignore = array(
'et_content',
'lingotek_push_once',
'lingotek_disabled',
'advanced',
'node_sync_status',
'document_id',
'prefill_phases_checkbox',
'prefill_phase_select',
);
$query = db_insert('lingotek')
->fields(array(
'nid',
'lingokey',
'lingovalue',
));
foreach ($node->lingotek as $key => $value) {
if (array_search($key, $ignore) === FALSE) {
$query
->values(array(
$node->nid,
$key,
$value,
));
}
}
$query
->execute();
// check for a workflow change
if (isset($node->lingotek['workflow_id']) && isset($node->lingotek['advanced']['document_id'])) {
$curr_workflow = $node->lingotek['workflow_id'];
$document_id = $node->lingotek['advanced']['document_id'];
if (!isset($node->original->lingotek['workflow_id']) || $node->original->lingotek['workflow_id'] != $curr_workflow) {
$api = LingotekApi::instance();
$prefill_checked = isset($node->lingotek['prefill_phases_checkbox']) ? $node->lingotek['prefill_phases_checkbox'] : NULL;
$prefill_phase = $prefill_checked ? $node->lingotek['prefill_phase_select'] : NULL;
$result = $api
->changeWorkflow(array(
$document_id,
), $curr_workflow, $prefill_phase);
LingotekSync::setAllTargetStatus($node->nid, LingotekSync::STATUS_PENDING);
}
}
}
else {
// Specific Profile
$node_defaults = lingotek_load_profile_defaults('node');
$profile_overridden = !isset($node_defaults[$node->type]['profile']) || $node_defaults[$node->type]['profile'] != $node->lingotek['profile'];
if ($profile_overridden) {
lingotek_lingonode($node->nid, 'profile', $node->lingotek['profile']);
}
else {
lingotek_lingonode_variable_delete($node->nid, 'profile');
}
}
//This reloads the lingovalues to ensure that the proper defaults and hierarchy are used.
//We clear out the lingovalues first, then wrap in an array, call the lingotek load function, and then unwrap from array.
unset($node->lingotek);
$nodes = array(
$node->nid => $node,
);
$types = array(
$node->type,
);
lingotek_node_load($nodes, $types);
$node = $nodes[$node->nid];
return $node;
}