-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook_example.pages.inc
89 lines (75 loc) · 2.31 KB
/
hook_example.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
<?php
function joke_edit($jid) {
$joke = get_joke_by_id($jid);
$output = drupal_get_form('joke_edit_form', $joke);
return $output;
}
function joke_add_form($form, &$form_state) {
$form['title'] = [
'#type' => 'markup',
'#markup' => "<h2 class='full-width'>Joke Add Form</h2>",
'#weight' => 0
];
$form['value'] = [
'#type' => 'textarea',
'#description' => t('Tell your joke above! No super long jokes because nobody cares about your jokes.'),
'#title' => t('Tell Joke Here'),
'#rows' => 3,
'#cols' => 70,
'#default_value' => isset($form_state['values']['value']) ? $form_state['values']['value'] : '',
'#weight' => 1
];
$form['submit'] = [
'#type' => 'submit',
//'#submit' => array('joke_add_submit'),
'#value' => t('Add Joke'),
'#weight' => 50
];
return $form;
}
function joke_add_form_submit($form, &$form_state) {
$values = $form_state['values'];
if (!empty($values)) {
drupal_set_message("Made it this far");
if (isset($values['value'])) {
$joke = new stdClass();
$joke->value = $values['value'];
$joke->created = time();
$joke->rating = 0;
drupal_set_message("Tried to create this joke..." . PHP_EOL . print_r($joke, TRUE));
joke_create($joke);
}
}
}
/**
* Form constructor for the node joke confirmation form.
*
* @see joke_delete_confirm_submit()
*/
function joke_delete_confirm($form, &$form_state, $joke) {
$form['#joke'] = $joke;
// Always provide entity id in the same form key as in the entity edit form.
$form['jid'] = array('#type' => 'value', '#value' => $joke->jid);
return confirm_form($form,
t('Are you sure you want to delete %title?', array('%title' => $joke->value)),
'joke/' . $joke->jid,
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Executes joke deletion.
*
* @see joke_delete_confirm()
*/
function joke_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$joke = node_load($form_state['values']['jid']);
joke_delete($form_state['values']['jid']);
cache_clear_all();
watchdog('content', 'Joke: deleted %title.', array('%title' => $joke->value));
drupal_set_message(t('Joke %title has been deleted.', array('%title' => $joke->value)));
}
$form_state['redirect'] = '<front>';
}