function lingotek_get_workbench_url in Lingotek Translation 7.2
Same name and namespace in other branches
- 7.7 lingotek.remote.inc \lingotek_get_workbench_url()
- 7.3 lingotek.api.inc \lingotek_get_workbench_url()
- 7.4 lingotek.api.inc \lingotek_get_workbench_url()
- 7.5 lingotek.remote.inc \lingotek_get_workbench_url()
- 7.6 lingotek.remote.inc \lingotek_get_workbench_url()
Get the url to open the Lingotek Workbench.
This fetches a link.
Parameters
object $node: A Drupal node.
$lingotek_locale: A target language.
mixed $label: The label to use as text for the link. Possible values are TRUE, FALSE, or a string to use as a the custom label for the link.
bool $force: Force the link to use the label of the first returned workflow phase for the target Document.
Return value
string Either a link pointing the the url, or the url itself if $label is FALSE
3 calls to lingotek_get_workbench_url()
- lingotek_form_node_form_alter in ./
lingotek.module - Implements hook_form_BASE_FORM_ID_alter().
- lingotek_node_view in ./
lingotek.module - Implements hook_node_view().
- lingotek_pm in ./
lingotek.page.inc - Page callback for the Lingotek local task on node detail pages.
File
- ./
lingotek.api.inc, line 396
Code
function lingotek_get_workbench_url($node, $lingotek_locale, $label = FALSE, $force = FALSE) {
if ($lingotek_locale === FALSE) {
return "";
}
$api = LingotekApi::instance();
$link = array();
$document_id = lingotek_lingonode($node->nid, 'document_id');
$targets = lingotek_get_document_targets($document_id, TRUE);
//Make sure we get the current phases for the links and not out of date ones (so caches don't combine)
if (count($targets) == 0) {
return '';
}
foreach ($targets as $lang => $translation_target) {
if ($lang != $lingotek_locale) {
continue;
}
lingotek_trace('lingotek_get_workbench_url TARGETS', array(
'lang' => $lang,
'translation_target' => $translation_target,
));
$target = $api
->getTranslationTarget($translation_target->id);
$phases = $target ? $target->phases : array();
$phase_id = -1;
$which_phase = 0;
foreach ($phases as $phase) {
if (!$phase->isMarkedComplete || $force) {
$phase_id = $phase->id;
break;
}
$which_phase++;
}
// All phases are complete, use last phase as current.
if (!empty($phases) && $phase_id == -1) {
$last_phase = end($phases);
$phase_id = $last_phase->id;
}
$l = '';
if ($phase_id != -1) {
$document_id = lingotek_lingonode($node->nid, 'document_id');
if ($document_id && ($workbench_url = $api
->getWorkbenchLink($document_id, $phase_id))) {
if ($label === FALSE) {
$l = $workbench_url;
}
else {
$path = $workbench_url;
if ($label === TRUE) {
$label = lingotek_get_phase_name($phase_id);
}
$l = l($label, '', array(
'attributes' => array(
'onclick' => 'window.open(\'' . $path . '\'); return false;',
'onmouseover' => 'jQuery("#node-' . $node->nid . '").addClass("highlight");',
'onmouseout' => 'jQuery("#node-' . $node->nid . '").removeClass("highlight");',
),
));
}
}
}
$link[$lang] = array(
'which_phase' => $which_phase,
'link' => $l,
);
}
return $link[$lingotek_locale]['link'];
}