function globallink_entity_node_presave in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_entity/globallink_entity.module \globallink_entity_node_presave()
- 7.6 globallink_entity/globallink_entity.module \globallink_entity_node_presave()
Implements hook_node_presave().
File
- globallink_entity/
globallink_entity.module, line 33 - GlobalLink entity translation module.
Code
function globallink_entity_node_presave($node) {
if (isset($node->tpt_skip) && $node->tpt_skip == TRUE || !isset($node->type)) {
return;
}
if (!entity_translation_node_supported_type($node->type)) {
return;
}
if (!isset($node->original)) {
return;
}
$handler = entity_translation_get_handler(GLOBALLINK_ENTITY_TYPE_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_entity($node, $lang);
break 2;
}
break 1;
case 'metatags':
continue 2;
}
$field_info = field_info_field($field_name);
switch ($field_info['type']) {
case 'list_boolean':
case 'image':
case 'file':
case 'taxonomy_term_reference':
case 'field_collection':
continue 2;
break;
}
if (!isset($node->{$field_name}) || !isset($orig->{$field_name})) {
globallink_update_change_detection_entity($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_entity($node, $lang);
continue;
}
if (!is_array($o_arr) || !is_array($n_arr)) {
if ($o_arr != $n_arr) {
globallink_update_change_detection_entity($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_entity($node, $lang);
break;
}
if (isset($o_arr[$lang]) && empty($n_arr[$lang]) || empty($o_arr[$lang]) && isset($n_arr[$lang])) {
globallink_update_change_detection_entity($node, $lang);
break;
}
if (count($o_arr[$lang]) != count($n_arr[$lang])) {
globallink_update_change_detection_entity($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_entity($node, $lang);
break 2;
}
}
else {
globallink_update_change_detection_entity($node, $lang);
break 2;
}
}
}
}