-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook_example.admin.inc
84 lines (76 loc) · 2.06 KB
/
hook_example.admin.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
<?php
function joke_admin() {
return drupal_get_form('joke_overview_list_page');
}
function joke_overview_list_page($form, &$form_state) {
// First let's build an add new Joke button
$form['add_joke'] = [
'#type' => 'link',
'#title' => t('Add New Joke'),
'#href' => 'joke/add',
'#attributes' => array('class' => array('button', 'action-button')),
//'#markup' => "<a class='button action-button'>Add New Joke</a>",
];
$headers = [
'Joke ID',
'Rating',
'Joke',
'Created',
'Operations'
];
$jokes = [];
$destination = drupal_get_destination();
// Now let's grab all the jokes from the database
$query = db_select('jokes', 'j')->extend('PagerDefault')->extend('TableSort');
$query->fields('j', array('jid', 'rating', 'value', 'created'));
$query->orderBy('j.created');
$query->limit(50);
$results = $query->execute();
// We have results!
if (!empty($results)) {
foreach ($results as $record) {
$jokes[$record->jid] = [
'joke_id' => [
'data' => [
'#type' => 'link',
'#title' => $record->jid,
'#href' => 'joke/' . $record->jid
],
],
'rating' => [
'data' => [
'#type' => 'text',
'#title' => $record->rating,
],
],
'joke' => [
'data' => [
'#type' => 'text',
'#value' => $record->value,
],
],
'created' => [
'data' => [
'#type' => 'text',
'#value' => format_date($record->created, 'short'),
],
],
'operations' => [
'data' => [
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'joke/' . $record->jid . '/edit',
'#options' => array('query' => $destination),
],
]
];
}
}
$form['jokes'] = array(
'#type' => 'tableselect',
'#header' => $headers,
'#options' => $jokes,
'#empty' => t('No jokes available.'),
);
$form['pager'] = array('#theme' => 'pager');
}