function globallink_entity_update in GlobalLink Connect for Drupal 7.5
Updates entity.
Parameters
object $globallink: GlobalLink object.
array $t_arr: The translated array. Defaults to NULL.
1 call to globallink_entity_update()
- globallink_entity_get_translated_enties in globallink_entity/
globallink_entity.inc - Gets number of translated entities.
File
- globallink_entity/
globallink_entity.inc, line 646
Code
function globallink_entity_update(&$globallink, $t_arr = NULL) {
module_load_include('inc', 'globallink', 'globallink');
try {
$target_lang = globallink_get_drupal_locale_code($globallink->targetLocale);
if ($t_arr != NULL) {
$translated_arr = $t_arr;
}
else {
$translated_arr = globallink_entity_get_translated_array($globallink->targetXML, $target_lang);
}
$target_nid = $translated_arr['nid'];
$target_vid = $translated_arr['vid'];
$globallink->nid = $target_nid;
$globallink->vid = $target_vid;
$node = node_load($target_nid, $target_vid);
if (isset($translated_arr['title'])) {
$node->title = $translated_arr['title'];
}
if (isset($node->title_original) && $node->title != $node->title_original) {
$node->title = $node->title_original;
}
if (!$node || is_null($node) || !is_object($node)) {
$globallink->status = 'Source Deleted';
return;
}
$nodepath = drupal_lookup_path('alias', 'node/' . $target_nid);
if ($nodepath) {
if (!empty($translated_arr['path'])) {
$path = array(
'alias' => $translated_arr['path'],
'source' => 'node/' . $target_nid,
'language' => $target_lang,
);
}
else {
$path = array(
'alias' => $nodepath,
'source' => 'node/' . $target_nid,
'language' => $target_lang,
);
}
if (module_exists('pathauto')) {
$path['pathauto'] = FALSE;
}
path_save($path);
}
$node->revision = 1;
if (module_exists('revisioning')) {
$node->is_pending = FALSE;
$node->revision_moderation = FALSE;
}
// Node presave hook skip
$node->tpt_skip = TRUE;
if (module_exists('metatag')) {
if (isset($translated_arr['metatag'])) {
$target_metatag_arr = $translated_arr['metatag'];
if (!empty($node->metatags[$node->language])) {
$metatags_names = array_keys($node->metatags[$node->language]);
$n_metatag =& $node->metatags;
foreach ($metatags_names as $name) {
if (isset($target_metatag_arr[$name]) && isset($target_metatag_arr[$name][0])) {
$gl_obj = $target_metatag_arr[$name]['0'];
if (is_object($gl_obj)) {
$translated_content = $gl_obj->translatedContent;
}
else {
$translated_content = $gl_obj;
}
$n_metatag[$target_lang][$name] = array(
'value' => $translated_content,
);
}
}
}
}
}
$success = globallink_entity_save_translated_entity_with_fields($node, $translated_arr, $target_lang);
if ($success) {
// todo Pathauto Module Support
$globallink->status = 'Published';
}
else {
$globallink->status = 'Error';
}
} catch (Exception $e) {
$globallink->status = 'Error';
watchdog('GlobalLink', 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}