function globallink_menu_get_translated in GlobalLink Connect for Drupal 7.6
Same name and namespace in other branches
- 7.5 globallink_menu/globallink_menu.inc \globallink_menu_get_translated()
Gets number of translated menus.
Parameters
string $pd4: The project director details.
array $globallink_arr: Array of GlobalLink objects.
Return value
int The number of translated menus.
2 calls to globallink_menu_get_translated()
- globallink_auto_receive in ./
globallink.module - Automatically receives translated contents.
- globallink_menu_receive_form_submit in globallink_menu/
globallink_menu_receive.inc - Handles menu form submission.
File
- globallink_menu/
globallink_menu.inc, line 508
Code
function globallink_menu_get_translated($pd4, &$globallink_arr) {
module_load_include('inc', 'i18n_menu', 'i18n_menu.admin');
module_load_include('inc', 'globallink', 'globallink');
$count = 0;
$source_link = array(
'link_title' => 'No Title',
);
usort($globallink_arr, 'globallink_menu_sort_gl_objects_by_menu_order');
foreach ($globallink_arr as $globallink) {
$target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
if ($globallink->sourceDeleted) {
continue;
}
if (!isset($target_xml)) {
continue;
}
$count++;
$language = globallink_get_drupal_locale_code($globallink->targetLocale);
$arr = globallink_menu_get_translated_items($target_xml);
try {
$mlid = $arr['mlid'];
$t_link_title = $arr['link_title'];
$source_link = menu_link_load($mlid);
$parent_link = $source_link['plid'];
if ($parent_link != 0) {
$p_link = menu_link_load($parent_link);
$parent_tr = i18n_menu_link_load($p_link['link_path'], $language);
if (empty($parent_tr)) {
$count--;
globallink_menu_update_status($globallink, 'Error');
watchdog('GlobalLink', 'Cannot update as the parent %parent is not translated.', array(
'%parent' => $p_link['link_title'],
), WATCHDOG_ERROR);
form_set_error('', t('Could not update %t_link as translated parent was not found. Please check logs for more information', array(
'%t_link' => $source_link['link_title'],
)));
continue;
}
}
if ($source_link) {
$t_title = FALSE;
if (isset($source_link['options'])) {
if (isset($source_link['options']['attributes'])) {
if (isset($source_link['options']['attributes']['title'])) {
if ($source_link['options']['attributes']['title'] != '') {
$t_title = isset($arr['title']) ? $arr['title'] : FALSE;
}
}
}
}
$t_plid = 0;
if (isset($source_link['plid']) && $source_link['plid'] != 0) {
$plid = $source_link['plid'];
$p_source_link = menu_link_load($plid);
$p_path_arr = translation_path_get_translations($p_source_link['link_path']);
if (isset($p_path_arr[$language])) {
$p_target_link = i18n_menu_link_load($p_path_arr[$language], $language);
$t_plid = $p_target_link['mlid'];
}
elseif (isset($p_source_link['i18n_tsid']) && $p_source_link['i18n_tsid'] != 0) {
$i18n_arr = globallink_menu_get_i18n_menu_set($p_source_link['i18n_tsid']);
if (isset($i18n_arr[$language])) {
$menu_link_row = $i18n_arr[$language];
$t_plid = $menu_link_row->mlid;
}
}
}
$path_arr = translation_path_get_translations($source_link['link_path']);
$link_path = '';
if (!isset($path_arr[$language])) {
$link_path = $source_link['link_path'];
}
else {
$link_path = $path_arr[$language];
}
$t_link = NULL;
if (isset($source_link['i18n_tsid']) && $source_link['i18n_tsid'] != 0) {
$i18n_arr = globallink_menu_get_i18n_menu_set($source_link['i18n_tsid']);
if (isset($i18n_arr[$language])) {
$menu_link_row = $i18n_arr[$language];
$t_link = menu_link_load($menu_link_row->mlid);
}
}
if (is_array($t_link)) {
$t_link['link_title'] = $t_link_title;
$t_link['menu_name'] = $source_link['menu_name'];
$t_link['customized'] = $source_link['customized'];
$t_link['has_children'] = $source_link['has_children'];
$t_link['expanded'] = $source_link['expanded'];
$t_link['weight'] = $source_link['weight'];
$t_link['hidden'] = $source_link['hidden'];
if ($t_title && $t_link != '') {
if (isset($t_link['options'])) {
if (isset($t_link['options']['attributes'])) {
$t_link['options']['attributes']['title'] = $t_title;
}
else {
$t_link['options']['attributes'] = array(
'title' => $t_title,
);
}
}
}
}
else {
$t_link = array();
$t_link['link_title'] = $t_link_title;
$t_link['language'] = $language;
$t_link['link_path'] = $link_path;
$t_link['menu_name'] = $source_link['menu_name'];
$t_link['customized'] = $source_link['customized'];
$t_link['has_children'] = $source_link['has_children'];
$t_link['expanded'] = $source_link['expanded'];
$t_link['weight'] = $source_link['weight'];
$t_link['hidden'] = $source_link['hidden'];
if ($t_plid != 0) {
$t_link['plid'] = $t_plid;
}
if ($t_title) {
$t_link['options'] = array(
'attributes' => array(
'title' => $t_title,
),
'langcode' => $language,
);
}
}
menu_link_save($t_link);
$translation_set = $source_link['i18n_tsid'] ? i18n_translation_set_load($source_link['i18n_tsid']) : i18n_translation_set_create('menu_link');
$translation_set
->add_item($source_link, $source_link['language']);
$translation_set
->add_item($t_link, $language);
$translation_set
->save(TRUE);
globallink_menu_update_status($globallink);
}
else {
// Source Link is deleted
globallink_menu_update_status($globallink, 'Source Deleted');
}
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
} catch (SoapFault $se) {
$count--;
globallink_menu_update_status($globallink, 'Error');
watchdog('GlobalLink', 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
form_set_error('', t('Web Services Error: @faultcode - @faultstring', array(
'@faultcode' => $se->faultcode,
'@faultstring' => $se->faultstring,
)));
} catch (Exception $e) {
$count--;
globallink_menu_update_status($globallink, '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);
form_set_error('', t('Error: @message', array(
'@message' => $e
->getMessage(),
)));
}
}
return $count;
}