function globallink_fieldable_panels_get_translated in GlobalLink Connect for Drupal 7.6
Same name and namespace in other branches
- 7.5 globallink_fieldable_panels/globallink_fieldable_panels.inc \globallink_fieldable_panels_get_translated()
Gets number of translated fieldable panels.
Parameters
string $pd4: The project director details.
array $globallink_arr: Array of GlobalLink objects.
Return value
int The number of translated fieldable panels.
2 calls to globallink_fieldable_panels_get_translated()
- globallink_auto_receive in ./
globallink.module - Automatically receives translated contents.
- globallink_fieldable_panels_receive_form_submit in globallink_fieldable_panels/
globallink_fieldable_panels_receive.inc - Handles fieldable panels form submission.
File
- globallink_fieldable_panels/
globallink_fieldable_panels.inc, line 806
Code
function globallink_fieldable_panels_get_translated($pd4, &$globallink_arr) {
module_load_include('inc', 'globallink', 'globallink');
$count = 0;
foreach ($globallink_arr as $globallink) {
$target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
if ($globallink->sourceDeleted || empty($target_xml)) {
continue;
}
$count++;
$target_locale = globallink_get_drupal_locale_code($globallink->targetLocale);
$source_locale = globallink_get_drupal_locale_code($globallink->sourceLocale);
$translated_arr = globallink_fieldable_panels_get_translated_array($target_xml);
try {
$fpid = $translated_arr['fpid'];
unset($translated_arr['fpid']);
$entity = fieldable_panels_panes_load($fpid);
if (empty($entity)) {
globallink_fieldable_panels_update_status($globallink, 'Source Deleted');
continue;
}
$fields = globallink_fieldable_panels_pane_get_fields($entity->bundle);
foreach ($fields as $field) {
$field_def = field_read_field($field);
$t_field_lang = LANGUAGE_NONE;
if (empty($translated_arr[$field])) {
if (isset($entity->{$field}[$source_locale])) {
$entity->{$field}[$target_locale] = $entity->{$field}[$source_locale];
}
continue;
}
if (key($translated_arr[$field]) !== LANGUAGE_NONE) {
$t_field_lang = key($translated_arr[$field]);
}
if (empty($entity->{$field}[$target_locale]) && $target_locale != LANGUAGE_NONE) {
$entity->{$field}[$target_locale] = $entity->{$field}[$t_field_lang];
}
$t_field_arr = $translated_arr[$field][$source_locale];
foreach ($entity->{$field}[$target_locale] as $delta => $fp_field) {
if (empty($t_field_arr[$delta])) {
continue;
}
$translation = $t_field_arr[$delta]->translatedContent;
if ($field_def['type'] == 'link_field') {
$entity->{$field}[$target_locale][$delta]['title'] = $translation;
}
else {
$entity->{$field}[$target_locale][$delta]['value'] = $translation;
}
}
}
$entity->revision = 1;
$entity->translations->data[$target_locale] = array(
'language' => $target_locale,
// Target language
'source' => $source_locale,
// Source language
'uid' => $entity->uid,
'status' => variable_get('globallink_publish_node', 0),
// publish translation
'translate' => 0,
// Translation out of date
'created' => $entity->created,
);
$entity->translations->hook[$target_locale] = array(
'hook' => 'insert',
'date' => NULL,
);
fieldable_panels_panes_save($entity);
globallink_fieldable_panels_update_status($globallink);
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
} catch (SoapFault $se) {
$count--;
globallink_fieldable_panels_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_fieldable_panels_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;
}