1 |
ecd1141f
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Administrative page callbacks for the External Links module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Page callback: Form constructor for a form to list and reorder external link templates.
|
10 |
|
|
*
|
11 |
|
|
* @ingroup forms
|
12 |
|
|
* @see ext_links_menu()
|
13 |
|
|
* @see ext_links_admin_overview_submit()
|
14 |
|
|
*/
|
15 |
|
|
function ext_links_admin_overview($form) {
|
16 |
|
|
|
17 |
|
|
$link_templates = ext_links_templates();
|
18 |
|
|
|
19 |
|
|
$form['#tree'] = TRUE;
|
20 |
|
|
foreach ($link_templates as $id => $link_template) {
|
21 |
|
|
$form['link_templates'][$id]['title'] = array('#markup' => check_plain($link_template->title));
|
22 |
|
|
$form['link_templates'][$id]['link'] = array('#markup' => check_plain($link_template->link));
|
23 |
|
|
$form['link_templates'][$id]['glue'] = array('#markup' => check_plain($link_template->glue));
|
24 |
|
|
$form['link_templates'][$id]['category'] = array('#markup' => check_plain($link_template->category));
|
25 |
82e80b81
|
Andreas Kohlbecker
|
$form['link_templates'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/cdm_dataportal/ext_links/' . $link_template->id);
|
26 |
d259fad0
|
Andreas Kohlbecker
|
$form['link_templates'][$id]['status'] = array('#type' => 'link',
|
27 |
|
|
'#title' => $link_template->status == 1 ? t('disable') : t('enable'),
|
28 |
|
|
'#href' => 'admin/config/cdm_dataportal/ext_links/' . $link_template->id . '/status/' . ($link_template->status == 1 ? '0' : '1'));
|
29 |
ecd1141f
|
Andreas Kohlbecker
|
$form['link_templates'][$id]['weight'] = array(
|
30 |
|
|
'#type' => 'weight',
|
31 |
deba3cdd
|
Andreas Kohlbecker
|
'#title' => t('Weight for @title', array('@title' => $link_template->id)),
|
32 |
ecd1141f
|
Andreas Kohlbecker
|
'#title_display' => 'invisible',
|
33 |
|
|
'#default_value' => $link_template->weight,
|
34 |
|
|
);
|
35 |
82e80b81
|
Andreas Kohlbecker
|
$form['link_templates'][$id]['#attributes']['class'] = [];
|
36 |
|
|
if($link_template->status != 1){
|
37 |
|
|
$form['link_templates'][$id]['#attributes']['class'][] = 'disabled';
|
38 |
|
|
}
|
39 |
ecd1141f
|
Andreas Kohlbecker
|
}
|
40 |
|
|
$form['actions'] = array('#type' => 'actions');
|
41 |
|
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
|
42 |
|
|
return $form;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Form submission handler for filter_admin_overview().
|
47 |
|
|
*/
|
48 |
|
|
function ext_links_admin_overview_submit($form, &$form_state) {
|
49 |
|
|
foreach ($form_state['values']['formats'] as $id => $data) {
|
50 |
|
|
if (is_array($data) && isset($data['weight'])) {
|
51 |
|
|
// Only update if this is a form element with weight.
|
52 |
|
|
db_update('filter_format')
|
53 |
|
|
->fields(array('weight' => $data['weight']))
|
54 |
|
|
->condition('format', $id)
|
55 |
|
|
->execute();
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
filter_formats_reset();
|
59 |
|
|
drupal_set_message(t('The text format ordering has been saved.'));
|
60 |
|
|
}
|
61 |
|
|
|
62 |
82e80b81
|
Andreas Kohlbecker
|
/**
|
63 |
|
|
* Page callback: Displays external link template add/edit form.
|
64 |
|
|
*
|
65 |
|
|
* @param object|null $link_template
|
66 |
|
|
* (optional) An object representing an external link template, with the following properties:
|
67 |
|
|
* - title: The link title
|
68 |
|
|
* - link: The link url template.
|
69 |
|
|
* - glue: The string to concatenate name parts in the URL query string.
|
70 |
|
|
* - status: (optional) An integer indicating whether the ext link is
|
71 |
|
|
* enabled (1) or not (0). Defaults to 1.
|
72 |
|
|
* - weight: (optional) The weight of the external link, which controls its
|
73 |
|
|
* placement in external link block. If omitted, the weight is set to 0.
|
74 |
|
|
* Defaults to NULL.
|
75 |
|
|
*
|
76 |
|
|
* @return
|
77 |
|
|
* A form array.
|
78 |
|
|
*
|
79 |
|
|
* @see filter_menu()
|
80 |
|
|
*/
|
81 |
|
|
function ext_links_admin_link_template_page($link_template = NULL) {
|
82 |
deba3cdd
|
Andreas Kohlbecker
|
if (!isset($link_template->id)) {
|
83 |
82e80b81
|
Andreas Kohlbecker
|
drupal_set_title(t('Add external link'));
|
84 |
|
|
$link_template = (object) array(
|
85 |
|
|
'title' => NULL,
|
86 |
|
|
'link' => 'https://',
|
87 |
|
|
'glue' => '',
|
88 |
|
|
'weight' => 0,
|
89 |
|
|
'status' => 1
|
90 |
|
|
);
|
91 |
|
|
}
|
92 |
|
|
return drupal_get_form('ext_links_admin_link_template_form', $link_template);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
019d69fa
|
Andreas Kohlbecker
|
function ext_links_admin_appearance_page(){
|
96 |
|
|
|
97 |
|
|
drupal_set_title(t('Configure the appearance of external links'));
|
98 |
|
|
|
99 |
|
|
$form['ext_links_options'] = array(
|
100 |
|
|
'#type' => 'fieldset',
|
101 |
|
|
'#title' => t('External links appearance options'),
|
102 |
|
|
'#collapsible' => FALSE,
|
103 |
|
|
'#collapsed' => FALSE
|
104 |
|
|
);
|
105 |
|
|
$form['ext_links_options']['ext_links_appearance_grouped'] = [
|
106 |
|
|
'#type' => 'checkbox',
|
107 |
|
|
'#title' => t('Show external links grouped by category with headings.'),
|
108 |
|
|
'#default_value' => variable_get('ext_links_appearance_grouped', 1)
|
109 |
|
|
];
|
110 |
|
|
|
111 |
|
|
return system_settings_form($form);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
82e80b81
|
Andreas Kohlbecker
|
|
115 |
|
|
/**
|
116 |
|
|
* Form constructor for the External Link add/edit form.
|
117 |
|
|
*
|
118 |
|
|
* @param $link_template
|
119 |
|
|
* A link template object having the properties:
|
120 |
0a381a96
|
Andreas Kohlbecker
|
* - id: A machine-readable name representing the ID of the external link.
|
121 |
82e80b81
|
Andreas Kohlbecker
|
* If this corresponds to an existing external link, that format will be
|
122 |
|
|
* updated; otherwise, a new external link will be created.
|
123 |
|
|
* - title: The link title
|
124 |
|
|
* - link: The link url template.
|
125 |
|
|
* - glue: The string to concatenate name parts in the URL query string.
|
126 |
|
|
* - status: (optional) An integer indicating whether the ext link is
|
127 |
|
|
* enabled (1) or not (0). Defaults to 1.
|
128 |
|
|
* - weight: (optional) The weight of the external link, which controls its
|
129 |
|
|
* placement in external link block. If omitted, the weight is set to 0.
|
130 |
|
|
* Defaults to NULL.
|
131 |
|
|
*
|
132 |
|
|
* @see ext_links_admin_link_template_form_validate()
|
133 |
|
|
* @see ext_links_admin_link_template_form_submit()
|
134 |
|
|
* @ingroup forms
|
135 |
|
|
*/
|
136 |
|
|
function ext_links_admin_link_template_form($form, &$form_state, $link_template) {
|
137 |
|
|
|
138 |
0e38f1bf
|
Andreas Kohlbecker
|
$form['#link_template'] = $link_template;
|
139 |
82e80b81
|
Andreas Kohlbecker
|
$form['#tree'] = TRUE;
|
140 |
|
|
|
141 |
|
|
$form['id'] = array(
|
142 |
|
|
'#type' => 'machine_name',
|
143 |
|
|
'#required' => TRUE,
|
144 |
|
|
'#default_value' => $link_template->id,
|
145 |
|
|
'#maxlength' => 255,
|
146 |
|
|
'#machine_name' => array(
|
147 |
|
|
'exists' => 'ext_link_exists',
|
148 |
|
|
),
|
149 |
|
|
'#disabled' => !empty($link_template->id),
|
150 |
|
|
);
|
151 |
|
|
$form['title'] = array(
|
152 |
|
|
'#type' => 'textfield',
|
153 |
|
|
'#title' => t('Title'),
|
154 |
|
|
'#default_value' => $link_template->title,
|
155 |
|
|
'#description' => t('The text of the link that will be displayed.'),
|
156 |
|
|
'#required' => TRUE,
|
157 |
|
|
);
|
158 |
|
|
$form['link'] = array(
|
159 |
|
|
'#type' => 'textfield',
|
160 |
|
|
'#title' => t('Link'),
|
161 |
|
|
'#description' => t('The URL of the link to the external resource or service.
|
162 |
|
|
The species name parts will be appended to this string.<p>E.g.
|
163 |
|
|
<code>https://external-service.test/images?q=</code> will result in
|
164 |
|
|
<code>https://external-service.test/images?q=Bellis+perennis</code> when the glue string is set to "+"</p>'),
|
165 |
|
|
'#default_value' => $link_template->link,
|
166 |
|
|
'#required' => TRUE,
|
167 |
|
|
);
|
168 |
|
|
$form['glue'] = array(
|
169 |
|
|
'#type' => 'textfield',
|
170 |
|
|
'#title' => t('Glue'),
|
171 |
|
|
'#description' => t('The string used to concatenate genus and species name parts in the query string.'),
|
172 |
|
|
'#default_value' => $link_template->glue,
|
173 |
|
|
'#required' => false,
|
174 |
|
|
);
|
175 |
|
|
$form['status'] = array(
|
176 |
|
|
'#type' => 'checkbox',
|
177 |
|
|
'#title' => t('Enabled'),
|
178 |
|
|
'#default_value' => $link_template->status
|
179 |
|
|
);
|
180 |
|
|
$form['weight'] = array(
|
181 |
|
|
'#type' => 'weight',
|
182 |
|
|
'#title' => t('Weight'),
|
183 |
|
|
'#default_value' => $link_template->weight,
|
184 |
|
|
'#delta' => 10,
|
185 |
|
|
);
|
186 |
|
|
$form['actions'] = array('#type' => 'actions');
|
187 |
|
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
188 |
|
|
|
189 |
|
|
return $form;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/**
|
193 |
|
|
* Form submission handler for ext_links_admin_link_template_form().
|
194 |
|
|
*/
|
195 |
|
|
function ext_links_admin_link_template_form_submit($form, &$form_state) {
|
196 |
|
|
// Remove unnecessary values.
|
197 |
|
|
form_state_values_clean($form_state);
|
198 |
|
|
|
199 |
|
|
// Add the submitted form values to the text link_template, and save it.
|
200 |
|
|
$link_template = $form['#link_template'];
|
201 |
|
|
foreach ($form_state['values'] as $key => $value) {
|
202 |
|
|
$link_template->$key = $value;
|
203 |
|
|
}
|
204 |
|
|
$status = ext_links_save($link_template);
|
205 |
|
|
|
206 |
|
|
switch ($status) {
|
207 |
|
|
case SAVED_NEW:
|
208 |
|
|
drupal_set_message(t('Added external link %link_template.', array('%link_template' => $link_template->id)));
|
209 |
|
|
break;
|
210 |
|
|
|
211 |
|
|
case SAVED_UPDATED:
|
212 |
|
|
drupal_set_message(t('The text link_template %link_template has been updated.', array('%link_template' => $link_template->id)));
|
213 |
|
|
break;
|
214 |
|
|
}
|
215 |
0e38f1bf
|
Andreas Kohlbecker
|
|
216 |
|
|
drupal_goto('admin/config/cdm_dataportal/ext_links');
|
217 |
82e80b81
|
Andreas Kohlbecker
|
}
|
218 |
ecd1141f
|
Andreas Kohlbecker
|
|
219 |
b03fb28d
|
Andreas Kohlbecker
|
/**
|
220 |
|
|
* Sets the status of a link_template.
|
221 |
|
|
*
|
222 |
|
|
* Used as page callback in menu items.
|
223 |
|
|
*
|
224 |
|
|
* @param $link_template
|
225 |
|
|
* The link template
|
226 |
|
|
* @param $status
|
227 |
|
|
* The status value to set (values: 1 or 0)
|
228 |
|
|
*/
|
229 |
|
|
function ext_links_admin_link_template_set_status($link_template, $status){
|
230 |
|
|
$link_template->status = $status === 1 ? 1 : 0;
|
231 |
|
|
ext_links_save($link_template);
|
232 |
|
|
drupal_goto("admin/config/cdm_dataportal/ext_links");
|
233 |
|
|
}
|
234 |
|
|
|
235 |
ecd1141f
|
Andreas Kohlbecker
|
/**
|
236 |
|
|
* Returns HTML for the text format administration overview form.
|
237 |
|
|
*
|
238 |
|
|
* @param $variables
|
239 |
|
|
* An associative array containing:
|
240 |
|
|
* - form: A render element representing the form.
|
241 |
|
|
*
|
242 |
|
|
* @ingroup themeable
|
243 |
|
|
*/
|
244 |
|
|
function theme_ext_links_admin_overview($variables) {
|
245 |
82e80b81
|
Andreas Kohlbecker
|
|
246 |
|
|
drupal_add_css(drupal_get_path('module', 'ext_links'). '/ext-links.admin.css');
|
247 |
|
|
|
248 |
ecd1141f
|
Andreas Kohlbecker
|
$form = $variables['form'];
|
249 |
|
|
|
250 |
|
|
$rows = array();
|
251 |
|
|
foreach (element_children($form['link_templates']) as $id) {
|
252 |
82e80b81
|
Andreas Kohlbecker
|
$row_class_attributes = $form['link_templates'][$id]['#attributes']['class'];
|
253 |
|
|
$row_class_attributes[] = 'draggable';
|
254 |
ecd1141f
|
Andreas Kohlbecker
|
$form['link_templates'][$id]['weight']['#attributes']['class'] = array('text-format-order-weight');
|
255 |
|
|
$rows[] = array(
|
256 |
|
|
'data' => array(
|
257 |
|
|
drupal_render($form['link_templates'][$id]['title']),
|
258 |
|
|
drupal_render($form['link_templates'][$id]['link']),
|
259 |
|
|
drupal_render($form['link_templates'][$id]['glue']),
|
260 |
|
|
drupal_render($form['link_templates'][$id]['category']),
|
261 |
|
|
drupal_render($form['link_templates'][$id]['weight']),
|
262 |
d259fad0
|
Andreas Kohlbecker
|
drupal_render($form['link_templates'][$id]['configure']),
|
263 |
|
|
drupal_render($form['link_templates'][$id]['status']),
|
264 |
ecd1141f
|
Andreas Kohlbecker
|
),
|
265 |
82e80b81
|
Andreas Kohlbecker
|
'class' => $row_class_attributes,
|
266 |
ecd1141f
|
Andreas Kohlbecker
|
);
|
267 |
|
|
}
|
268 |
d259fad0
|
Andreas Kohlbecker
|
$header = array(t('Title'), t('Link'), t('Glue'), t('Category'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
|
269 |
ecd1141f
|
Andreas Kohlbecker
|
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'text-format-order')));
|
270 |
|
|
$output .= drupal_render_children($form);
|
271 |
|
|
|
272 |
|
|
drupal_add_tabledrag('text-format-order', 'order', 'sibling', 'text-format-order-weight');
|
273 |
|
|
|
274 |
|
|
return $output;
|
275 |
|
|
}
|