|
1 <?php |
|
2 |
|
3 /** |
|
4 * @file |
|
5 * User page callbacks for the Translation module. |
|
6 */ |
|
7 |
|
8 /** |
|
9 * Page callback: Displays a list of a node's translations. |
|
10 * |
|
11 * @param $node |
|
12 * A node object. |
|
13 * |
|
14 * @return |
|
15 * A render array for a page containing a list of content. |
|
16 * |
|
17 * @see translation_menu() |
|
18 */ |
|
19 function translation_node_overview($node) { |
|
20 include_once DRUPAL_ROOT . '/includes/language.inc'; |
|
21 |
|
22 if ($node->tnid) { |
|
23 // Already part of a set, grab that set. |
|
24 $tnid = $node->tnid; |
|
25 $translations = translation_node_get_translations($node->tnid); |
|
26 } |
|
27 else { |
|
28 // We have no translation source nid, this could be a new set, emulate that. |
|
29 $tnid = $node->nid; |
|
30 $translations = array(entity_language('node', $node) => $node); |
|
31 } |
|
32 |
|
33 $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); |
|
34 $header = array(t('Language'), t('Title'), t('Status'), t('Operations')); |
|
35 |
|
36 foreach (language_list() as $langcode => $language) { |
|
37 $options = array(); |
|
38 $language_name = $language->name; |
|
39 if (isset($translations[$langcode])) { |
|
40 // Existing translation in the translation set: display status. |
|
41 // We load the full node to check whether the user can edit it. |
|
42 $translation_node = node_load($translations[$langcode]->nid); |
|
43 $path = 'node/' . $translation_node->nid; |
|
44 $links = language_negotiation_get_switch_links($type, $path); |
|
45 $title = empty($links->links[$langcode]['href']) ? l($translation_node->title, $path) : l($translation_node->title, $links->links[$langcode]['href'], $links->links[$langcode]); |
|
46 if (node_access('update', $translation_node)) { |
|
47 $text = t('edit'); |
|
48 $path = 'node/' . $translation_node->nid . '/edit'; |
|
49 $links = language_negotiation_get_switch_links($type, $path); |
|
50 $options[] = empty($links->links[$langcode]['href']) ? l($text, $path) : l($text, $links->links[$langcode]['href'], $links->links[$langcode]); |
|
51 } |
|
52 $status = $translation_node->status ? t('Published') : t('Not published'); |
|
53 $status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : ''; |
|
54 if ($translation_node->nid == $tnid) { |
|
55 $language_name = t('<strong>@language_name</strong> (source)', array('@language_name' => $language_name)); |
|
56 } |
|
57 } |
|
58 else { |
|
59 // No such translation in the set yet: help user to create it. |
|
60 $title = t('n/a'); |
|
61 if (node_access('create', $node)) { |
|
62 $text = t('add translation'); |
|
63 $path = 'node/add/' . str_replace('_', '-', $node->type); |
|
64 $links = language_negotiation_get_switch_links($type, $path); |
|
65 $query = array('query' => array('translation' => $node->nid, 'target' => $langcode)); |
|
66 $options[] = empty($links->links[$langcode]['href']) ? l($text, $path, $query) : l($text, $links->links[$langcode]['href'], array_merge_recursive($links->links[$langcode], $query)); |
|
67 } |
|
68 $status = t('Not translated'); |
|
69 } |
|
70 $rows[] = array($language_name, $title, $status, implode(" | ", $options)); |
|
71 } |
|
72 |
|
73 drupal_set_title(t('Translations of %title', array('%title' => $node->title)), PASS_THROUGH); |
|
74 |
|
75 $build['translation_node_overview'] = array( |
|
76 '#theme' => 'table', |
|
77 '#header' => $header, |
|
78 '#rows' => $rows, |
|
79 ); |
|
80 |
|
81 return $build; |
|
82 } |