-
Notifications
You must be signed in to change notification settings - Fork 0
/
translation.pages.inc
102 lines (93 loc) · 3.48 KB
/
translation.pages.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @file
* User page callbacks for the Translation module.
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
/**
* Page callback: Displays a list of a node's translations.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* A node entity.
*
* @return
* A render array for a page containing a list of content.
*
* @see translation_menu()
*/
function translation_node_overview(EntityInterface $node) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
if ($node->tnid) {
// Already part of a set, grab that set.
$tnid = $node->tnid;
$translations = translation_node_get_translations($node->tnid);
}
else {
// We have no translation source nid, this could be a new set, emulate that.
$tnid = $node->nid;
$translations = array($node->langcode => $node);
}
$type = config('translation.settings')->get('language_type');
$header = array(t('Language'), t('Title'), t('Status'), t('Operations'));
foreach (language_list() as $langcode => $language) {
$options = array();
$language_name = $language->name;
if (isset($translations[$langcode])) {
// Existing translation in the translation set: display status.
// We load the full node to check whether the user can edit it.
$translation_node = node_load($translations[$langcode]->nid);
$path = 'node/' . $translation_node->id();
$links = language_negotiation_get_switch_links($type, $path);
$title = empty($links->links[$langcode]['href']) ? l($translation_node->label(), $path) : l($translation_node->label(), $links->links[$langcode]['href'], $links->links[$langcode]);
if (node_access('update', $translation_node)) {
$path = 'node/' . $translation_node->id() . '/edit';
$links = language_negotiation_get_switch_links($type, $path);
if (!empty($links->links[$langcode]['href'])) {
$options['edit'] = array(
'title' => t('edit'),
) + $links->links[$langcode];
}
}
$status = $translation_node->status ? t('Published') : t('Not published');
$status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : '';
if ($translation_node->id() == $tnid) {
$language_name = t('<strong>@language_name</strong> (source)', array('@language_name' => $language_name));
}
}
else {
// No such translation in the set yet: help user to create it.
$title = t('n/a');
if (node_access('create', $node)) {
$path = 'node/add/' . $node->type;
$links = language_negotiation_get_switch_links($type, $path);
$query = array('query' => array('translation' => $node->id(), 'target' => $langcode));
if (!empty($links->links[$langcode]['href'])) {
$options['add'] = array(
'title' => t('Add translation'),
) + $links->links[$langcode];
$options['add'] = NestedArray::mergeDeep($options['add'], $query);
}
}
$status = t('Not translated');
}
$row = array();
$row[] = $language_name;
$row[] = $title;
$row[] = $status;
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $options,
),
);
$rows[] = $row;
}
drupal_set_title(t('Translations of %title', array('%title' => $node->label())), PASS_THROUGH);
$build['translation_node_overview'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
return $build;
}