1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Internationalization (i18n) module. Translation sets admin
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Overview page for translation sets
|
10
|
*
|
11
|
* @param $type
|
12
|
* Translation set type to get a listing for this type only
|
13
|
* @param $query
|
14
|
* Base query to build upon
|
15
|
*/
|
16
|
function i18n_translation_admin_overview($type = NULL, $query = NULL) {
|
17
|
// Build the sortable table header.
|
18
|
$header['title'] = array('data' => t('Title'), 'field' => 't.title');
|
19
|
if (!$type) {
|
20
|
$header['type'] = array('data' => t('Type'), 'field' => 't.type');
|
21
|
}
|
22
|
$header['items'] = t('Items');
|
23
|
$header['created'] = array('data' => t('Created'), 'field' => 't.created');
|
24
|
$header['changed'] = array('data' => t('Updated'), 'field' => 't.changed', 'sort' => 'desc');
|
25
|
$header['operations'] = array('data' => t('Operations'));
|
26
|
|
27
|
// Get the translation sets for this form
|
28
|
$query = $query ? $query : db_select('i18n_translation_set', 't');
|
29
|
$query = $query->extend('PagerDefault')->extend('TableSort');
|
30
|
if ($type) {
|
31
|
$query->condition('t.type', $type);
|
32
|
}
|
33
|
$tsids = $query
|
34
|
->fields('t', array('tsid'))
|
35
|
->limit(20)
|
36
|
->orderByHeader($header)
|
37
|
->execute()
|
38
|
->fetchCol();
|
39
|
$translations = $tsids ? entity_load('i18n_translation', $tsids) : array();
|
40
|
|
41
|
$form = drupal_get_form('i18n_translation_admin_form', $translations, $header);
|
42
|
|
43
|
$form['pager'] = array('#markup' => theme('pager'));
|
44
|
return $form;
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Admin form
|
49
|
*/
|
50
|
function i18n_translation_admin_form($form, &$form_state, $translations, $header) {
|
51
|
$destination = drupal_get_destination();
|
52
|
$rows = array();
|
53
|
foreach ($translations as $set) {
|
54
|
$info = i18n_object_info($set->type);
|
55
|
$rows[$set->tsid]['title'] = check_plain($set->get_title());
|
56
|
if (isset($header['type'])) {
|
57
|
$rows[$set->tsid]['type'] = isset($info['title']) ? $info['title'] : t('Unknown');
|
58
|
}
|
59
|
$rows[$set->tsid]['items'] = ($items = $set->get_links()) ? theme('links', array('links' => $items)) : '';
|
60
|
$rows[$set->tsid] += array(
|
61
|
'created' => format_date($set->created, 'short'),
|
62
|
'changed' => format_date($set->changed, 'short'),
|
63
|
'operations' => '',
|
64
|
);
|
65
|
|
66
|
// Build a list of all the accessible operations for the current set.
|
67
|
$operations = $set->get_operations();
|
68
|
if (count($operations) > 1) {
|
69
|
// Render an unordered list of operations links.
|
70
|
$rows[$set->tsid]['operations'] = array(
|
71
|
'data' => array(
|
72
|
'#theme' => 'links__node_operations',
|
73
|
'#links' => $operations,
|
74
|
'#attributes' => array('class' => array('links', 'inline')),
|
75
|
),
|
76
|
);
|
77
|
}
|
78
|
elseif (!empty($operations)) {
|
79
|
// Render the first and only operation as a link.
|
80
|
$link = reset($operations);
|
81
|
$rows[$set->tsid]['operations'] = array(
|
82
|
'data' => array(
|
83
|
'#type' => 'link',
|
84
|
'#title' => $link['title'],
|
85
|
'#href' => $link['href'],
|
86
|
'#options' => array('query' => $link['query']),
|
87
|
),
|
88
|
);
|
89
|
}
|
90
|
}
|
91
|
$form['translations'] = array(
|
92
|
'#theme' => 'table',
|
93
|
'#header' => $header,
|
94
|
'#rows' => $rows,
|
95
|
'#empty' => t('No translation sets available.'),
|
96
|
);
|
97
|
return $form;
|
98
|
}
|