-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess_unpublished.admin.inc
75 lines (70 loc) · 3.01 KB
/
access_unpublished.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
<?php
/**
* @file
* Admin page callbacks for Access unpublished.
*/
/**
* Form constructor for system setting.
*/
function access_unpublished_url_param_form($form) {
$form['access_unpublished_url_key'] = array(
'#type' => 'textfield',
'#title' => t('URL hash parameter'),
'#default_value' => config_get('access_unpublished.settings', 'access_unpublished_url_key'),
'#description' => t('Set the URL parameter for hashed key,
for example: http://example.com/node/1?<strong>hash</strong>=abc...,
example.com/node/1?<strong>key</strong>=abc...'),
'#maxlength' => 20,
'#size' => 10,
);
$form['access_unpublished_display_link'] = array(
'#type' => 'fieldset',
'#title' => t('Display hashed link to unpublished node in:'),
);
$form['access_unpublished_display_link']['access_unpublished_display_link_in_message'] = array(
'#type' => 'checkbox',
'#title' => t('Backdrop message'),
'#default_value' => config_get('access_unpublished.settings', 'access_unpublished_display_link_in_message'),
);
$form['access_unpublished_display_link']['access_unpublished_display_link_in_node_content'] = array(
'#type' => 'checkbox',
'#title' => t('Node content'),
'#description' => t('Use template access-unpublished-link.tpl.php
and access_unpublished.css for custom design.'),
'#default_value' => config_get('access_unpublished.settings', 'access_unpublished_display_link_in_node_content'),
);
// Add a submit button
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Form validation handler for access_unpublished_url_param_form().
*
* Pass only ASCII characters.
* At least one display option must be checked.
*/
function access_unpublished_url_param_form_validate($form, &$form_state) {
$access_unpublished_url_key = $form_state['values']['access_unpublished_url_key'];
if (preg_match('/^[a-zA-Z0-9]+$/', $access_unpublished_url_key) != 1) {
form_set_error('access_unpublished_url_key', t('Only ASCII characters can be used as URL key'));
}
if (!$form_state['values']['access_unpublished_display_link_in_message']
&& !$form_state['values']['access_unpublished_display_link_in_node_content']) {
form_set_error('access_unpublished_display_link', t('At least one display option must be checked.'));
}
}
/**
* Submit handler for module_settings_form().
*/
function access_unpublished_url_param_form_submit($form, &$form_state) {
$config = config('access_unpublished.settings');
$config->set('access_unpublished_url_key', $form_state['values']['access_unpublished_url_key']);
$config->set('access_unpublished_display_link_in_message', $form_state['values']['access_unpublished_display_link_in_message']);
$config->set('access_unpublished_display_link_in_node_content', $form_state['values']['access_unpublished_display_link_in_node_content']);
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}