-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook_example.module
75 lines (63 loc) · 1.79 KB
/
hook_example.module
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
<?php
function hook_example_menu() {
$items = [];
$items['joke/list'] = [
'title' => 'Jokes',
'description' => 'List and edit site jokes.',
'page callback' => 'joke_admin',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'file' => 'hook_example.admin.inc',
];
$items['joke/add'] = [
'title' => 'Add New Joke',
'description' => 'Returns the add new Joke form',
'page callback' => 'drupal_get_form',
'page arguments' => array('joke_add_form'),
'access callback' => TRUE,
'file' => 'hook_example.pages.inc'
];
$items['joke/%joke'] = [
'title callback' => 'joke_title',
'title arguments' => array(1),
'description' => 'View a joke on the site',
'page callback' => 'joke_view',
'page arguments' => array(1),
];
$items['joke/%joke/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('joke_delete_confirm', 1),
'access callback' => TRUE,
'weight' => 1,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'file' => 'hook_example.pages.inc',
);
return $items;
}
function get_joke_by_id($jid) {
$query = db_select('jokes', 'j');
$query->fields('j', ['jid', 'value', 'created', 'rating']);
$query->condition('j.jid', $jid, '=');
$results = $query->execute()->fetchAssoc();
return $results;
}
function joke_create($joke) {
$joke = (object) $joke;
if ($joke->value) {
module_invoke_all('joke_presave', $joke);
drupal_set_message(print_r($joke, TRUE));
$record = [
'rating' => $joke->rating,
'created' => $joke->created,
'value' => $joke->value
];
drupal_write_record('jokes', $record);
}
}
function joke_delete($jid) {
db_delete('jokes')
->condition('jid', $jid)
->execute();
}