-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathding_nodelist.admin.inc
131 lines (111 loc) · 4.13 KB
/
ding_nodelist.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @file
* Administration interface for nodelist configuration.
*/
/**
* General settings form.
*/
function ding_nodelist_settings_form() {
$options = node_type_get_names();
if (empty($options)) {
drupal_set_message(t('No content types were found, please add one first.'), 'error', FALSE);
}
$form['ding_nodelist_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Available content types'),
'#options' => $options,
'#default_value' => variable_get('ding_nodelist_node_types', array()),
'#description' => t('Choose content types avaialable for display'),
);
// Options as defiend by panels/plugins/cache/simple.inc
$options = drupal_map_assoc(array(15, 30, 60, 120, 180, 240, 300, 600, 900, 1200, 1800, 3600, 7200, 14400, 28800, 43200, 86400, 172800, 259200, 345600, 604800), 'format_interval');
$form['ding_nodelist_cache_default_time'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Default cache life time'),
'#default_value' => variable_get('ding_nodelist_cache_default_time', NL_CACHE_LIFETIME),
'#description' => t('Lists will be cached by default for this period of time (seconds)'),
);
$form['ding_nodelist_autoscroll_delay'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#title' => t('Autoscroll delay'),
'#description' => t('The delay to show an item for various nodelist widgets (in milliseconds).'),
);
$autoscrolling_widgets = array(
NL_WIDGET_CAROUSEL => array('Carousel', 3000),
NL_WIDGET_HOR_ACCORDION => array('Horizontal accordion', 3000),
);
foreach ($autoscrolling_widgets as $widget => $conf) {
$title = isset($conf[0]) ? t(check_plain($conf[0])) : '';
$form['ding_nodelist_autoscroll_delay']['ding_nodelist_' . $widget . '_delay'] = array(
'#type' => 'textfield',
'#title' => $title,
'#default_value' => variable_get('ding_nodelist_' . $widget . '_delay', $conf[1]),
'#size' => 5,
);
}
return system_settings_form($form);
}
/**
* Template settings form.
*/
function ding_nodelist_templates_form($form, &$form_state) {
$form['templates'] = array(
'#type' => 'fieldset',
'#title' => t('Templates'),
'#tree' => TRUE,
'#theme' => '_ding_nodelist_templates_table',
);
$templates = _ding_nodelist_get_templates();
foreach ($templates as $template_name => $template) {
$form['templates'][$template_name]['template_name'] = array(
'#type' => 'hidden',
'#value' => $template_name,
);
$form['templates'][$template_name]['title'] = array(
'#type' => 'textfield',
'#default_value' => isset($template['title']) ? $template['title'] : '',
'#size' => 40,
);
$ct = node_type_get_names();
$form['templates'][$template_name]['content_type'] = array(
'#markup' => isset($ct[$template['content_type']]) ?
$ct[$template['content_type']] : t('Missing (@ctname)', array('@ctname' => $template['content_type'])),
);
$widgets = _ding_nodelist_get_widget_types();
$form['templates'][$template_name]['widget'] = array(
'#type' => 'select',
'#empty_option' => t('- select -'),
'#required' => FALSE,
'#default_value' => isset($template['widget']) ? $template['widget'] : '',
'#options' => $widgets,
);
// Visible in list of templates?
$form['templates'][$template_name]['visible'] = array(
'#type' => 'checkbox',
'#default_value' => $template['status'] == NL_TPL_ACTIVE ? TRUE : FALSE,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Writes details about found templates.
*/
function ding_nodelist_templates_form_submit($form, &$form_state) {
foreach ($form_state['values']['templates'] as $template) {
$tpl_record = array(
'title' => $template['title'],
'status' => $template['visible'] ? NL_TPL_ACTIVE : NL_TPL_HIDDEN,
'widget' => $template['widget'],
);
db_update('ding_nodelist_templates')->fields($tpl_record)
->condition('filename', $template['template_name'])->execute();
}
drupal_set_message(t('Template settings have been saved.'));
}