function globallink_node_presave in GlobalLink Connect for Drupal 7.6
Same name and namespace in other branches
- 7.7 globallink.module \globallink_node_presave()
- 7.5 globallink.module \globallink_node_presave()
Implements hook_node_presave().
File
- ./
globallink.module, line 934 - GlobalLink translation module.
Code
function globallink_node_presave($node) {
if (isset($node->tpt_skip) && $node->tpt_skip == TRUE) {
return;
}
if (!translation_supported_type($node->type)) {
return;
}
if (!isset($node->original)) {
return;
}
$handler = entity_translation_get_handler("node", $node);
$config_fields = globallink_get_translatable_fields($node->type, $node->type);
$orig = $node->original;
$lang = $handler
->getFormLanguage();
foreach ($config_fields as $field) {
if ($field->translatable != 1) {
continue;
}
$field_name = $field->field_name;
switch ($field_name) {
case 'title':
if ($orig->title != $node->title) {
globallink_update_change_detection($node, $lang);
break 2;
}
break 1;
case 'metatags':
continue 2;
}
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'list_boolean' && $field_info['type'] == 'image' && $field_info['type'] == 'file' && $field_info['type'] == 'taxonomy_term_reference' && $field_info['type'] == 'field_collection') {
continue;
}
if (!isset($node->{$field_name}) || !isset($orig->{$field_name})) {
globallink_update_change_detection($node, $lang);
break;
}
$o_arr = isset($orig->{$field_name}) ? $orig->{$field_name} : array();
$n_arr = isset($node->{$field_name}) ? $node->{$field_name} : array();
if (empty($o_arr) || empty($n_arr) || count($o_arr) != count($n_arr)) {
globallink_update_change_detection($node, $lang);
continue;
}
if (!is_array($o_arr) || !is_array($n_arr)) {
if ($o_arr != $n_arr) {
globallink_update_change_detection($node, $lang);
break;
}
continue;
}
if (empty($o_arr[$lang]) && empty($n_arr[$lang]) && isset($o_arr[LANGUAGE_NONE]) && isset($n_arr[LANGUAGE_NONE])) {
$lang = LANGUAGE_NONE;
}
if (isset($o_arr[$lang]) && isset($n_arr[$lang]) && count($o_arr[$lang]) != count($n_arr[$lang])) {
globallink_update_change_detection($node, $lang);
break;
}
if (isset($o_arr[$lang]) && empty($n_arr[$lang]) || empty($o_arr[$lang]) && isset($n_arr[$lang])) {
globallink_update_change_detection($node, $lang);
break;
}
if (count($o_arr[$lang]) != count($n_arr[$lang])) {
globallink_update_change_detection($node, $lang);
break;
}
foreach ($o_arr[$lang] as $delta => $n_field) {
if (isset($n_arr[$lang][$delta]) && isset($n_arr[$lang][$delta]['value'])) {
if ($n_field['value'] != $n_arr[$lang][$delta]['value']) {
globallink_update_change_detection($node, $lang);
break 2;
}
}
else {
globallink_update_change_detection($node, $lang);
break 2;
}
}
}
}