| 1 |
<?php
|
| 2 |
// $Id: taxonomy_filter.admin.inc,v 1.7 2009/05/29 21:12:45 solotandem Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The administration settings pages for the Taxonomy Filter module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
// TODO: are we overusing variable_get and variable_set? Is clearing the variable cache too costly?
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Menu callback for module settings form.
|
| 13 |
*/
|
| 14 |
function taxonomy_filter_admin_list() {
|
| 15 |
// should menu settings get processed here instead of the form generator?
|
| 16 |
return drupal_get_form('taxonomy_filter_admin_list_form');
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Form builder.
|
| 21 |
*/
|
| 22 |
function taxonomy_filter_admin_list_form($form_state) {
|
| 23 |
$templates = _taxonomy_filter_menu_templates(FALSE);
|
| 24 |
$template_names = array();
|
| 25 |
foreach ($templates as $name => $template) {
|
| 26 |
$template_names[$name] = $name;
|
| 27 |
}
|
| 28 |
$menus = _taxonomy_filter_menu_list(FALSE, FALSE);
|
| 29 |
|
| 30 |
$form = array();
|
| 31 |
|
| 32 |
// Menu template summary.
|
| 33 |
$form['templates'] = array(
|
| 34 |
'#type' => 'fieldset',
|
| 35 |
'#title' => t('Menu templates'),
|
| 36 |
'#description' => t('Menu templates provide for different ways of:<ol><li>selecting the taxonomy terms to display.</li><li>displaying the selected taxonomy terms.</li></ol>'),
|
| 37 |
);
|
| 38 |
$form['templates']['table'] = array(
|
| 39 |
'#theme' => 'taxonomy_filter_admin_list_form_templates',
|
| 40 |
);
|
| 41 |
foreach ($templates as $key => $template) {
|
| 42 |
$form['templates']['table'][$key] = array(
|
| 43 |
'name' => array('#value' => $template['name']),
|
| 44 |
'desc' => array('#value' => $template['desc']),
|
| 45 |
'module' => array('#value' => $template['module name']),
|
| 46 |
'status' => array('#value' => ucfirst($template['status']), '#class' => $template['status']),
|
| 47 |
);
|
| 48 |
}
|
| 49 |
|
| 50 |
// Menu summary.
|
| 51 |
$form['menus'] = array(
|
| 52 |
'#type' => 'fieldset',
|
| 53 |
'#title' => t('Menus'),
|
| 54 |
'#description' => t('The following filter menus have been defined for use with the indicated vocabularies.'),
|
| 55 |
);
|
| 56 |
$form['menus']['table'] = array(
|
| 57 |
'#theme' => 'taxonomy_filter_admin_list_form_menus',
|
| 58 |
);
|
| 59 |
foreach ($menus as $key => $menu) {
|
| 60 |
if ($menu['status'] == 'enabled') {
|
| 61 |
$edit = l(t('edit'), "admin/settings/taxonomy_filter/$key/edit");
|
| 62 |
}
|
| 63 |
else {
|
| 64 |
$edit = t('edit');
|
| 65 |
}
|
| 66 |
$vocabs = (is_array($menu['vocabs'])) ? implode(', ', $menu['vocabs']) : '';
|
| 67 |
$form['menus']['table'][$key] = array(
|
| 68 |
'name' => array('#value' => check_plain($menu['name'])),
|
| 69 |
'template' => array('#value' => $menu['template']),
|
| 70 |
'edit' => array('#value' => $edit),
|
| 71 |
'delete' => array('#value' => l(t('delete'), "admin/settings/taxonomy_filter/$key/delete")),
|
| 72 |
'vocabs' => array('#value' => $vocabs),
|
| 73 |
'status' => array('#value' => ucfirst($menu['status']), '#class' => $menu['status']),
|
| 74 |
);
|
| 75 |
}
|
| 76 |
|
| 77 |
// Add menu.
|
| 78 |
$form['add'] = array(
|
| 79 |
'#type' => 'fieldset',
|
| 80 |
'#title' => t('Add menu'),
|
| 81 |
'#description' => t('Add a filter menu based on a menu template.'),
|
| 82 |
);
|
| 83 |
$form['add']['new_name'] = array(
|
| 84 |
'#type' => 'textfield',
|
| 85 |
'#title' => t('Name'),
|
| 86 |
'#size' => 40,
|
| 87 |
'#required' => TRUE,
|
| 88 |
);
|
| 89 |
$form['add']['new_template'] = array(
|
| 90 |
'#type' => 'select',
|
| 91 |
'#title' => t('Menu template'),
|
| 92 |
'#default_value' => 'base',
|
| 93 |
'#options' => $template_names,
|
| 94 |
'#required' => TRUE,
|
| 95 |
);
|
| 96 |
$form['add']['submit'] = array(
|
| 97 |
'#type' => 'submit',
|
| 98 |
'#value' => t('Add menu'),
|
| 99 |
);
|
| 100 |
|
| 101 |
return $form;
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Submit handler.
|
| 106 |
*/
|
| 107 |
function taxonomy_filter_admin_list_form_submit($form, &$form_state) {
|
| 108 |
$name = $form_state['values']['new_name'];
|
| 109 |
$template = $form_state['values']['new_template'];
|
| 110 |
|
| 111 |
$all_templates = _taxonomy_filter_menu_templates(FALSE);
|
| 112 |
$module = $all_templates[$template]['module'];
|
| 113 |
_taxonomy_filter_menu_create($name, $template, $module);
|
| 114 |
}
|
| 115 |
|
| 116 |
/**
|
| 117 |
* Form builder.
|
| 118 |
*/
|
| 119 |
function taxonomy_filter_admin_general() {
|
| 120 |
$settings = variable_get('taxonomy_filter_general', array());
|
| 121 |
$settings += array(
|
| 122 |
'current_block_title' => TAXONOMY_FILTER_CURRENT_BLOCK_TITLE,
|
| 123 |
'refine_block_title' => TAXONOMY_FILTER_REFINE_BLOCK_TITLE,
|
| 124 |
'display_current_atop_content' => FALSE,
|
| 125 |
);
|
| 126 |
|
| 127 |
$form = array();
|
| 128 |
$form['current_block_title'] = array(
|
| 129 |
'#type' => 'textfield',
|
| 130 |
'#title' => t('Current criteria block title'),
|
| 131 |
'#default_value' => $settings['current_block_title'],
|
| 132 |
'#description' => t('Title to display for "Taxonomy filter - current criteria" block.'),
|
| 133 |
);
|
| 134 |
$form['refine_block_title'] = array(
|
| 135 |
'#type' => 'textfield',
|
| 136 |
'#title' => t('Refine criteria block title'),
|
| 137 |
'#default_value' => $settings['refine_block_title'],
|
| 138 |
'#description' => t('Title to display for "Taxonomy filter - refine criteria" block.'),
|
| 139 |
);
|
| 140 |
$form['display_current_atop_content'] = array(
|
| 141 |
'#type' => 'checkbox',
|
| 142 |
'#title' => t('Display current criteria block above content'),
|
| 143 |
'#default_value' => $settings['display_current_atop_content'],
|
| 144 |
'#description' => t('By default, this block will display the links inline as opposed to a list, cloud, etc.'),
|
| 145 |
);
|
| 146 |
$form['submit'] = array(
|
| 147 |
'#type' => 'submit',
|
| 148 |
'#value' => t('Save settings'),
|
| 149 |
'#weight' => 20,
|
| 150 |
);
|
| 151 |
|
| 152 |
return $form;
|
| 153 |
}
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Submit handler.
|
| 157 |
*/
|
| 158 |
function taxonomy_filter_admin_general_submit($form, &$form_state) {
|
| 159 |
$settings = variable_get('taxonomy_filter_general', array());
|
| 160 |
|
| 161 |
$settings['current_block_title'] = $form_state['values']['current_block_title'];
|
| 162 |
$settings['refine_block_title'] = $form_state['values']['refine_block_title'];
|
| 163 |
$settings['display_current_atop_content'] = $form_state['values']['display_current_atop_content'];
|
| 164 |
|
| 165 |
variable_set('taxonomy_filter_general', $settings);
|
| 166 |
drupal_set_message(t('Updated the general settings.'));
|
| 167 |
}
|
| 168 |
|
| 169 |
/**
|
| 170 |
* Menu callback for module settings form.
|
| 171 |
*/
|
| 172 |
function taxonomy_filter_admin_mappings() {
|
| 173 |
taxonomy_filter_update_mappings(); // TODO Is this necessary??? It sets default values for all vocabulary mappings.
|
| 174 |
return drupal_get_form('taxonomy_filter_admin_mappings_form');
|
| 175 |
}
|
| 176 |
|
| 177 |
/**
|
| 178 |
* Form builder.
|
| 179 |
*/
|
| 180 |
function taxonomy_filter_admin_mappings_form($form_state) {
|
| 181 |
$names = /* array('None') + */ _taxonomy_filter_menu_list(FALSE, TRUE, TRUE);
|
| 182 |
$menus = _taxonomy_filter_menu_list(FALSE, FALSE);
|
| 183 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 184 |
$vocabs = _taxonomy_filter_get_vocabs();
|
| 185 |
|
| 186 |
$form = array();
|
| 187 |
$form['mappings'] = array(
|
| 188 |
'#type' => 'fieldset',
|
| 189 |
'#title' => t('Menu mappings'),
|
| 190 |
'#description' => t('For each vocabulary, you can specify:'.
|
| 191 |
'<ol><li>which menu type is used to render it in the "Taxonomy filter" blocks (refine and current criteria).</li>'.
|
| 192 |
'<li>which taxonomy listings this menu should appear on.</li></ol>'),
|
| 193 |
);
|
| 194 |
$form['mappings']['table'] = array(
|
| 195 |
'#theme' => 'taxonomy_filter_admin_mappings_table',
|
| 196 |
);
|
| 197 |
foreach ($mappings as $row_vid => $row_settings) {
|
| 198 |
$form['mappings']['table']['vocab'. $row_vid] = array('#value' => check_plain($row_settings['vocab']));
|
| 199 |
$form['mappings']['table']['refine_menu'. $row_vid] = array(
|
| 200 |
'#type' => 'select',
|
| 201 |
'#default_value' => $row_settings['refine_menu'],
|
| 202 |
'#options' => array('None') + $names,
|
| 203 |
);
|
| 204 |
$form['mappings']['table']['current_menu'. $row_vid] = array(
|
| 205 |
'#type' => 'select',
|
| 206 |
'#default_value' => $row_settings['current_menu'],
|
| 207 |
'#options' => array('Same') + $names,
|
| 208 |
);
|
| 209 |
$vocab_names = array();
|
| 210 |
if (isset($row_settings['mappings'])) {
|
| 211 |
foreach ($row_settings['mappings'] as $mapping) {
|
| 212 |
$vocab_names[] = $vocabs[$mapping];
|
| 213 |
}
|
| 214 |
}
|
| 215 |
$vocab_names = (is_array($vocab_names)) ? implode(', ', $vocab_names) : '';
|
| 216 |
|
| 217 |
$form['mappings']['table']['vocabs'. $row_vid] = array('#value' => check_plain($vocab_names));
|
| 218 |
$edit = l(t('edit'), "admin/settings/taxonomy_filter/mappings/$row_vid/edit");
|
| 219 |
$form['mappings']['table']['edit'. $row_vid] = array('#title' => t('Menu mappings'), '#value' => $edit);
|
| 220 |
}
|
| 221 |
if (!$mappings) {
|
| 222 |
drupal_set_message(t('No vocabularies have been defined to be mapped. Add vocabularies <b><a href="@url">here</a></b> and then return to this page to define mappings.', array('@url' => '/admin/content/taxonomy')), 'warning');
|
| 223 |
}
|
| 224 |
if (!$menus) {
|
| 225 |
drupal_set_message(t('No menus have been defined to be mapped. Add menus <b><a href="@url">here</a></b> and then return to this page to define mappings.', array('@url' => '/admin/settings/taxonomy_filter')), 'warning');
|
| 226 |
}
|
| 227 |
if ($mappings && $menus) {
|
| 228 |
$form['submit'] = array(
|
| 229 |
'#type' => 'submit',
|
| 230 |
'#value' => t('Save settings'),
|
| 231 |
);
|
| 232 |
}
|
| 233 |
return $form;
|
| 234 |
}
|
| 235 |
|
| 236 |
/**
|
| 237 |
* Submit handler.
|
| 238 |
*/
|
| 239 |
function taxonomy_filter_admin_mappings_form_submit($form, &$form_state) {
|
| 240 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 241 |
foreach ($mappings as $vid => &$mapping) {
|
| 242 |
$mapping['refine_menu'] = $form_state['values']['refine_menu'. $vid];
|
| 243 |
$mapping['current_menu'] = $form_state['values']['current_menu'. $vid];
|
| 244 |
}
|
| 245 |
variable_set('taxonomy_filter_mappings', $mappings);
|
| 246 |
drupal_set_message(t('Updated the criteria menus.'));
|
| 247 |
}
|
| 248 |
|
| 249 |
/**
|
| 250 |
* Form builder.
|
| 251 |
*/
|
| 252 |
function taxonomy_filter_admin_mappings_edit_form($form_state, $vid) {
|
| 253 |
if (!is_numeric($vid)) {
|
| 254 |
drupal_not_found();
|
| 255 |
exit;
|
| 256 |
}
|
| 257 |
$vocabs = _taxonomy_filter_get_vocabs();
|
| 258 |
if (!array_key_exists($vid, $vocabs)) {
|
| 259 |
drupal_not_found();
|
| 260 |
exit;
|
| 261 |
}
|
| 262 |
|
| 263 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 264 |
|
| 265 |
drupal_set_title(t('Edit mappings for %vocabulary vocabulary', array('%vocabulary' => $mappings[$vid]['vocab'])));
|
| 266 |
|
| 267 |
$form = array();
|
| 268 |
$form['vid'] = array(
|
| 269 |
'#type' => 'value',
|
| 270 |
'#value' => $vid,
|
| 271 |
);
|
| 272 |
$multiple = TRUE;
|
| 273 |
$description = 'Display the filter menu for this vocabulary on term listings from the selected vocabularies. To clear the mappings for this vocabulary, select "None" and click "Save settings" or click the "Clear settings" button.';
|
| 274 |
$form['vocabs'] = array(
|
| 275 |
'#type' => 'select',
|
| 276 |
'#title' => 'Vocabularies',
|
| 277 |
'#default_value' => isset($mappings[$vid]['mappings']) ? $mappings[$vid]['mappings'] : array(),
|
| 278 |
'#options' => array(0 => '<None>') + $vocabs,
|
| 279 |
'#description' => $description,
|
| 280 |
'#multiple' => $multiple,
|
| 281 |
'#size' => $multiple ? min(12, count($vocabs) + 1) : 0,
|
| 282 |
'#weight' => -15,
|
| 283 |
);
|
| 284 |
$form['save'] = array(
|
| 285 |
'#type' => 'submit',
|
| 286 |
'#value' => t('Save settings'),
|
| 287 |
);
|
| 288 |
$form['clear'] = array(
|
| 289 |
'#type' => 'submit',
|
| 290 |
'#value' => t('Clear settings'),
|
| 291 |
);
|
| 292 |
return $form;
|
| 293 |
}
|
| 294 |
|
| 295 |
/**
|
| 296 |
* Validation handler.
|
| 297 |
*/
|
| 298 |
function taxonomy_filter_admin_mappings_edit_form_validate($form, &$form_state) {
|
| 299 |
if ($form_state['values']['op'] == $form_state['values']['save']) {
|
| 300 |
if (count($form_state['values']['vocabs']) == 0) {
|
| 301 |
form_set_error('vocabs', t('Please select an item in the list before clicking the "Save settings" button.'));
|
| 302 |
}
|
| 303 |
if (count($form_state['values']['vocabs']) > 1 && in_array(0, $form_state['values']['vocabs'])) {
|
| 304 |
form_set_error('vocabs', t('You have selected "None" along with one or more vocabularies.'));
|
| 305 |
}
|
| 306 |
}
|
| 307 |
}
|
| 308 |
|
| 309 |
/**
|
| 310 |
* Submit handler.
|
| 311 |
*/
|
| 312 |
function taxonomy_filter_admin_mappings_edit_form_submit($form, &$form_state) {
|
| 313 |
$vid = $form_state['values']['vid'];
|
| 314 |
|
| 315 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 316 |
if ($form_state['values']['op'] == $form_state['values']['clear'] || in_array(0, $form_state['values']['vocabs'])) {
|
| 317 |
$mappings[$vid]['mappings'] = array();
|
| 318 |
}
|
| 319 |
else {
|
| 320 |
$mappings[$vid]['mappings'] = array_values($form_state['values']['vocabs']);
|
| 321 |
}
|
| 322 |
variable_set('taxonomy_filter_mappings', $mappings);
|
| 323 |
|
| 324 |
$form_state['redirect'] = 'admin/settings/taxonomy_filter/mappings';
|
| 325 |
drupal_set_message(t('Updated the vocabulary mappings.'));
|
| 326 |
}
|
| 327 |
|
| 328 |
/**
|
| 329 |
* Form builder.
|
| 330 |
*/
|
| 331 |
function taxonomy_filter_admin_advanced() {
|
| 332 |
$form = array();
|
| 333 |
$form['urls'] = array(
|
| 334 |
'#type' => 'fieldset',
|
| 335 |
'#title' => t('URL settings'),
|
| 336 |
);
|
| 337 |
$form['urls']['intro'] = array(
|
| 338 |
'#value' => t('<p>You should only need to change these settings '.
|
| 339 |
'if this module\'s blocks are to integrate with URLs from other taxonomy modules '.
|
| 340 |
'- see the README.txt file for more information. The default values should work well for most sites.</p>'),
|
| 341 |
);
|
| 342 |
$form['urls']['taxonomy_filter_input'] = array(
|
| 343 |
'#type' => 'textarea',
|
| 344 |
'#title' => t('URLs to listen on'),
|
| 345 |
'#default_value' => variable_get('taxonomy_filter_input', TAXONOMY_FILTER_INPUT),
|
| 346 |
'#required' => TRUE,
|
| 347 |
'#description' => t('<p>A list of taxonomy listing URL patterns to listen for. '.
|
| 348 |
'You will only need to change this if you have configured non-standard '.
|
| 349 |
'taxonomy listings (e.g. with the Taxonomy Menu or Views modules).</p>'),
|
| 350 |
);
|
| 351 |
$form['urls']['taxonomy_filter_output'] = array(
|
| 352 |
'#type' => 'textfield',
|
| 353 |
'#title' => t('URL format to output in links'),
|
| 354 |
'#default_value' => variable_get('taxonomy_filter_output', TAXONOMY_FILTER_OUTPUT),
|
| 355 |
'#required' => TRUE,
|
| 356 |
'#description' => t('<p>Format of the taxonomy listing URLs created by Taxonomy Filter. '.
|
| 357 |
'You will only need to change this if you have configured non-standard '.
|
| 358 |
'taxonomy listings (e.g. with the Taxonomy Menu or Views modules).</p>'),
|
| 359 |
);
|
| 360 |
$form['save'] = array(
|
| 361 |
'#type' => 'submit',
|
| 362 |
'#value' => t('Save settings'),
|
| 363 |
);
|
| 364 |
$form['reset'] = array(
|
| 365 |
'#type' => 'submit',
|
| 366 |
'#value' => t('Reset to defaults'),
|
| 367 |
);
|
| 368 |
return $form;
|
| 369 |
/*
|
| 370 |
// TODO: handle own caching
|
| 371 |
|
| 372 |
$form['caching'] = array('#type' => 'fieldset',
|
| 373 |
'#title' => t('block cache settings'),
|
| 374 |
);
|
| 375 |
$form['caching']['flags'] = array(
|
| 376 |
'#type' => 'radios',
|
| 377 |
'#title' => t('cache level'),
|
| 378 |
'#default_value' => variable_get('taxonomy_filter_cache', 2),
|
| 379 |
'#options' => array(
|
| 380 |
t('no caching'),
|
| 381 |
t('cache per user'),
|
| 382 |
t('cache per role'),
|
| 383 |
t('global cache'),
|
| 384 |
),
|
| 385 |
);
|
| 386 |
*/
|
| 387 |
}
|
| 388 |
|
| 389 |
/**
|
| 390 |
* Submit handler.
|
| 391 |
*
|
| 392 |
* Break the input filter patterns into component pieces.
|
| 393 |
*/
|
| 394 |
function taxonomy_filter_admin_advanced_submit($form, &$form_state) {
|
| 395 |
if ($form_state['values']['op'] == $form_state['values']['reset']) {
|
| 396 |
$filters = TAXONOMY_FILTER_INPUT;
|
| 397 |
variable_del('taxonomy_filter_input');
|
| 398 |
variable_del('taxonomy_filter_output');
|
| 399 |
}
|
| 400 |
else {
|
| 401 |
$filters = $form_state['values']['taxonomy_filter_input'];
|
| 402 |
variable_set('taxonomy_filter_input', $filters);
|
| 403 |
variable_set('taxonomy_filter_output', $form_state['values']['taxonomy_filter_output']);
|
| 404 |
}
|
| 405 |
taxonomy_filter_parse_input_filters($filters);
|
| 406 |
|
| 407 |
drupal_set_message(t('Updated the advanced settings.'));
|
| 408 |
}
|
| 409 |
|
| 410 |
/**
|
| 411 |
* Form builder.
|
| 412 |
*/
|
| 413 |
function taxonomy_filter_admin_menu_edit_form(&$form_state, $menu_id) {
|
| 414 |
if (!is_numeric($menu_id)) {
|
| 415 |
drupal_not_found();
|
| 416 |
exit;
|
| 417 |
}
|
| 418 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 419 |
if (!array_key_exists($menu_id, $menus)) {
|
| 420 |
drupal_not_found();
|
| 421 |
exit;
|
| 422 |
}
|
| 423 |
$module = $menus[$menu_id]['module'];
|
| 424 |
|
| 425 |
$form = array();
|
| 426 |
$form['menu_id'] = array(
|
| 427 |
'#type' => 'value',
|
| 428 |
'#value' => $menu_id,
|
| 429 |
);
|
| 430 |
// Store this for other modules to test in their form_alter hook.
|
| 431 |
$form['module'] = array(
|
| 432 |
'#type' => 'value',
|
| 433 |
'#value' => $module,
|
| 434 |
);
|
| 435 |
$form['name'] = array(
|
| 436 |
'#type' => 'textfield',
|
| 437 |
'#title' => t('Menu name'),
|
| 438 |
'#default_value' => $menus[$menu_id]['name'],
|
| 439 |
);
|
| 440 |
$form['template_name'] = array(
|
| 441 |
'#type' => 'item',
|
| 442 |
'#title' => t('Menu template'),
|
| 443 |
'#value' => $menus[$menu_id]['template'],
|
| 444 |
);
|
| 445 |
$form['depth'] = array('#type' => 'select',
|
| 446 |
'#title' => t('Listing depth'),
|
| 447 |
'#multiple' => False,
|
| 448 |
'#default_value' => $menus[$menu_id]['depth'],
|
| 449 |
'#options' => array(
|
| 450 |
t('Not specified (ie use default)'),
|
| 451 |
1, 2, 3, 4, 5,
|
| 452 |
'all' => t('Show all levels'),
|
| 453 |
),
|
| 454 |
'#description' => t('How many levels of child terms to show in listings.'),
|
| 455 |
);
|
| 456 |
|
| 457 |
// TODO This seems like it duplicates the form_alter hook. Remove?
|
| 458 |
$template_settings = module_invoke($module, 'tf_settings');
|
| 459 |
if (is_array($template_settings)) {
|
| 460 |
$form += $template_settings;
|
| 461 |
}
|
| 462 |
// TODO If a 'tf_settings' function exists, it can set a submit hook. Remove this.
|
| 463 |
// Also, statement following this if block overrides the if block.
|
| 464 |
// if (function_exists($module .'_tf_settings_submit')) { // use module_hook instead?
|
| 465 |
// $form['#submit'][] = $module .'_tf_settings_submit';
|
| 466 |
// }
|
| 467 |
$form['submit'] = array(
|
| 468 |
'#type' => 'submit',
|
| 469 |
'#value' => t('Save settings'),
|
| 470 |
'#weight' => 20,
|
| 471 |
);
|
| 472 |
return $form;
|
| 473 |
}
|
| 474 |
|
| 475 |
/**
|
| 476 |
* Submit handler.
|
| 477 |
*/
|
| 478 |
function taxonomy_filter_admin_menu_edit_form_submit($form, &$form_state) {
|
| 479 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 480 |
$menu_id = $form_state['values']['menu_id'];
|
| 481 |
|
| 482 |
$menus[$menu_id]['name'] = $form_state['values']['name'];
|
| 483 |
$menus[$menu_id]['depth'] = $form_state['values']['depth'];
|
| 484 |
|
| 485 |
variable_set('taxonomy_filter_menus', $menus);
|
| 486 |
$form_state['redirect'] = 'admin/settings/taxonomy_filter';
|
| 487 |
drupal_set_message(t('Updated menu %name.', array('%name' => $form_state['values']['name'])));
|
| 488 |
}
|
| 489 |
|
| 490 |
/**
|
| 491 |
* Form builder.
|
| 492 |
*/
|
| 493 |
function taxonomy_filter_admin_menu_delete_confirm(&$form_state, $id) {
|
| 494 |
if (!is_numeric($id)) {
|
| 495 |
return drupal_access_denied();
|
| 496 |
}
|
| 497 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 498 |
$name = $menus[$id]['name'];
|
| 499 |
$form['menu_id'] = array('#type' => 'value', '#value' => $id);
|
| 500 |
$form['menu_name'] = array('#type' => 'value', '#value' => $name);
|
| 501 |
$message = t('Are you sure you want to delete the taxonomy filter menu %name?', array('%name' => $name));
|
| 502 |
$caption = '<p>'. t('This action cannot be undone.') .'</p>';
|
| 503 |
return confirm_form($form, $message, 'admin/settings/taxonomy_filter', $caption, t('Delete'));
|
| 504 |
}
|
| 505 |
|
| 506 |
/**
|
| 507 |
* Submit handler.
|
| 508 |
*/
|
| 509 |
function taxonomy_filter_admin_menu_delete_confirm_submit($form, &$form_state) {
|
| 510 |
// Reset mappings to 'None' for the filter menu.
|
| 511 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 512 |
$mid = $form_state['values']['menu_id'];
|
| 513 |
foreach ($mappings as $vid => &$mapping) {
|
| 514 |
if ($mapping['refine_menu'] == $mid) {
|
| 515 |
$mapping['refine_menu'] = '0';
|
| 516 |
}
|
| 517 |
if ($mapping['current_menu'] == $mid) {
|
| 518 |
$mapping['current_menu'] = '0';
|
| 519 |
}
|
| 520 |
}
|
| 521 |
variable_set('taxonomy_filter_mappings', $mappings);
|
| 522 |
|
| 523 |
// Delete the filter menu.
|
| 524 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 525 |
unset($menus[$form_state['values']['menu_id']]);
|
| 526 |
variable_set('taxonomy_filter_menus', $menus);
|
| 527 |
|
| 528 |
$t_args = array('%name' => $form_state['values']['menu_name']);
|
| 529 |
drupal_set_message(t('Deleted menu %name.', $t_args));
|
| 530 |
watchdog('taxonomy filter', 'Deleted menu %name.', $t_args, WATCHDOG_NOTICE);
|
| 531 |
|
| 532 |
$form_state['redirect'] = 'admin/settings/taxonomy_filter';
|
| 533 |
}
|
| 534 |
|
| 535 |
/**
|
| 536 |
* Submit callback for taxonomy_filter_admin_list_form_submit.
|
| 537 |
*
|
| 538 |
* @param string $name Menu name.
|
| 539 |
* @param string $template Menu template to use.
|
| 540 |
* @param string $module Name of module implementing menu template.
|
| 541 |
*/
|
| 542 |
function _taxonomy_filter_menu_create($name, $template, $module) {
|
| 543 |
// Create menu.
|
| 544 |
$menu = array(
|
| 545 |
'name' => $name,
|
| 546 |
'template' => $template,
|
| 547 |
'module' => $module,
|
| 548 |
'depth' => '0',
|
| 549 |
);
|
| 550 |
|
| 551 |
// Add default values for enabled submodules.
|
| 552 |
$modules = module_implements('tf_default_settings');
|
| 553 |
foreach ($modules as $module) {
|
| 554 |
$menu[$module] = module_invoke($module, 'tf_default_settings');
|
| 555 |
}
|
| 556 |
|
| 557 |
// Save variable.
|
| 558 |
$menus = variable_get('taxonomy_filter_menus', array()); // TODO: change to get_menu??
|
| 559 |
// Set first index to one, o/w add one to last index.
|
| 560 |
$keys = array_keys($menus);
|
| 561 |
$key = ($keys) ? $keys[count($keys) - 1] + 1 : 1;
|
| 562 |
$menus[$key] = $menu;
|
| 563 |
variable_set('taxonomy_filter_menus', $menus);
|
| 564 |
drupal_set_message(t('Added menu %name.', array('%name' => $name)));
|
| 565 |
}
|
| 566 |
|
| 567 |
/**
|
| 568 |
* Return list of menu templates.
|
| 569 |
*
|
| 570 |
* @todo Remove the parameter?
|
| 571 |
* @param boolean $names_only
|
| 572 |
* @return array List of menu templates.
|
| 573 |
*/
|
| 574 |
function _taxonomy_filter_menu_templates($names_only = TRUE) {
|
| 575 |
static $templates;
|
| 576 |
|
| 577 |
if (is_null($templates)) {
|
| 578 |
// Get complete information the first time so we can handle all requests.
|
| 579 |
$modules = module_implements('tf_template_info');
|
| 580 |
$templates = array();
|
| 581 |
foreach ($modules as $module) {
|
| 582 |
$tfinfo = module_invoke($module, 'tf_template_info');
|
| 583 |
$info_file = drupal_parse_info_file(drupal_get_path('module', $module) .'/'. $module .'.info');
|
| 584 |
$name = ($tfinfo['name']) ? $tfinfo['name'] : $info_file['name'];
|
| 585 |
$status = _taxonomy_filter_module_status($module);
|
| 586 |
$templates[$name] = array(
|
| 587 |
'name' => $name,
|
| 588 |
'desc' => ($tfinfo['desc']) ? $tfinfo['desc'] : $info_file['description'],
|
| 589 |
'module' => $module,
|
| 590 |
'module name' => $info_file['name'],
|
| 591 |
'status' => $status,
|
| 592 |
);
|
| 593 |
}
|
| 594 |
}
|
| 595 |
|
| 596 |
if ($names_only) {
|
| 597 |
$names = array();
|
| 598 |
foreach ($templates as $name => $template) {
|
| 599 |
$names[$name] = $name;
|
| 600 |
}
|
| 601 |
return $names;
|
| 602 |
}
|
| 603 |
return $templates;
|
| 604 |
}
|
| 605 |
|
| 606 |
/**
|
| 607 |
* Return list of menus.
|
| 608 |
*
|
| 609 |
* @param boolean $enabled_only
|
| 610 |
* @param boolean $names_only
|
| 611 |
* @param boolean $warning_in_name
|
| 612 |
* @return array List of menus.
|
| 613 |
*/
|
| 614 |
function _taxonomy_filter_menu_list($enabled_only = TRUE, $names_only = TRUE, $warning_in_name = FALSE) {
|
| 615 |
$templates = _taxonomy_filter_menu_templates();
|
| 616 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 617 |
$menu_vocabs = _taxonomy_filter_menu_vocabs();
|
| 618 |
|
| 619 |
$results = array();
|
| 620 |
foreach ($menus as $id => $menu) {
|
| 621 |
// TODO: Check this expression for accuracy and possible simplifications.
|
| 622 |
// It should leave out disabled templates only if required.
|
| 623 |
if (!($enabled_only && !in_array($menu['template'], $templates))) {
|
| 624 |
$status = _taxonomy_filter_module_status($menu['module']);
|
| 625 |
if ($names_only) {
|
| 626 |
if ($warning_in_name && $status != 'enabled') {
|
| 627 |
$results[$id] = $menu['name'] .' ('. $status .')';
|
| 628 |
}
|
| 629 |
else {
|
| 630 |
$results[$id] = $menu['name'];
|
| 631 |
}
|
| 632 |
}
|
| 633 |
else {
|
| 634 |
$results[$id] = array(
|
| 635 |
'name' => $menu['name'],
|
| 636 |
'template' => $menu['template'],
|
| 637 |
'module' => $menu['module'],
|
| 638 |
'status' => $status,
|
| 639 |
'vocabs' => isset($menu_vocabs[$id]) ? $menu_vocabs[$id] : '',
|
| 640 |
);
|
| 641 |
}
|
| 642 |
}
|
| 643 |
}
|
| 644 |
return $results;
|
| 645 |
}
|
| 646 |
|
| 647 |
/**
|
| 648 |
* Return list of vocabulary mappings keyed by menu template.
|
| 649 |
*
|
| 650 |
* @param integer $menu_id
|
| 651 |
* @return array List of vocabulary mappings keyed by menu template.
|
| 652 |
*/
|
| 653 |
function _taxonomy_filter_menu_vocabs($menu_id = NULL) {
|
| 654 |
static $menu_vocabs = array();
|
| 655 |
if (!$menu_vocabs) {
|
| 656 |
$mappings = variable_get('taxonomy_filter_mappings', array());
|
| 657 |
$vocabs = _taxonomy_filter_get_vocabs();
|
| 658 |
foreach ($mappings as $vid => $mapping) {
|
| 659 |
if ($mapping['refine_menu']) {
|
| 660 |
$menu_vocabs[$mapping['refine_menu']][] = $vocabs[$vid];
|
| 661 |
}
|
| 662 |
}
|
| 663 |
}
|
| 664 |
if ($menu_id) {
|
| 665 |
return $menu_vocabs[$menu_id];
|
| 666 |
}
|
| 667 |
else {
|
| 668 |
return $menu_vocabs;
|
| 669 |
}
|
| 670 |
}
|
| 671 |
|
| 672 |
/**
|
| 673 |
* Return module status.
|
| 674 |
*
|
| 675 |
* @param string $module Module name.
|
| 676 |
* @return string Status.
|
| 677 |
*/
|
| 678 |
function _taxonomy_filter_module_status($module) {
|
| 679 |
// either 'enabled', 'disabled', or 'missing'
|
| 680 |
if (module_exists($module)) {
|
| 681 |
return 'enabled'; // t('enabled');
|
| 682 |
}
|
| 683 |
if (drupal_get_filename('module', $module)) {
|
| 684 |
return 'disabled'; // t('disabled');
|
| 685 |
}
|
| 686 |
else {
|
| 687 |
return 'missing'; // t('missing');
|
| 688 |
}
|
| 689 |
}
|