| 1 |
<?php
|
| 2 |
// $Id: weblinks.taxonomy.inc,v 1.2 2008/07/23 19:40:04 nancyw Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Taxonomy Settings form.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Returns a form for adding a container to the weblink vocabulary.
|
| 11 |
*
|
| 12 |
* @param $edit Associative array containing a container term to be added or edited.
|
| 13 |
*/
|
| 14 |
function weblinks_form_container($form_state, $tid = 0) {
|
| 15 |
$edit = array('weight' => 0);
|
| 16 |
if ((is_numeric($tid)) && ($tid != 0)) {
|
| 17 |
$edit = (array)taxonomy_get_term($tid);
|
| 18 |
}
|
| 19 |
|
| 20 |
$form['name'] = array(
|
| 21 |
'#type' => 'textfield',
|
| 22 |
'#title' => t('Group Name'),
|
| 23 |
'#default_value' => $edit['name'],
|
| 24 |
'#maxlength' => 64,
|
| 25 |
'#description' => t('This Groups the links and allows you to sort them.'),
|
| 26 |
'#required' => TRUE,
|
| 27 |
);
|
| 28 |
|
| 29 |
$form['description'] = array(
|
| 30 |
'#type' => 'textarea',
|
| 31 |
'#title' => t('Group Description'),
|
| 32 |
'#default_value' => $edit['description'],
|
| 33 |
'#cols' => 60,
|
| 34 |
'#rows' => 5,
|
| 35 |
'#description' => t('The description can provide additional information about the link grouping.'),
|
| 36 |
);
|
| 37 |
|
| 38 |
$form['weight'] = array(
|
| 39 |
'#type' => 'weight',
|
| 40 |
'#title' => t('Weight'),
|
| 41 |
'#default_value' => $edit['weight'],
|
| 42 |
'#delta' => 10,
|
| 43 |
'#description' => t('In listings, the heavier terms (with a larger weight) will sink and the lighter terms will be positioned nearer the top.'),
|
| 44 |
);
|
| 45 |
$vocid = _weblinks_get_vocid();
|
| 46 |
$form['vid'] = array('#type' => 'hidden', '#value' => $vocid);
|
| 47 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
| 48 |
if ($tid) {
|
| 49 |
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
|
| 50 |
$form['tid'] = array('#type' => 'hidden', '#value' => $tid);
|
| 51 |
}
|
| 52 |
return $form;
|
| 53 |
}
|
| 54 |
|
| 55 |
/**
|
| 56 |
* Process forum form and container form submissions.
|
| 57 |
*/
|
| 58 |
function weblinks_form_container_submit($form, &$form_state) {
|
| 59 |
$container = TRUE;
|
| 60 |
$type = t('weblinks container');
|
| 61 |
if ($form_state['values']['delete'] == 'Delete') {
|
| 62 |
$status = taxonomy_del_term($form_state['values']['tid']);
|
| 63 |
}
|
| 64 |
else {
|
| 65 |
$status = taxonomy_save_term($form_state['values']);
|
| 66 |
}
|
| 67 |
switch ($status) {
|
| 68 |
case SAVED_NEW:
|
| 69 |
$containers = variable_get('weblinks_containers', array());
|
| 70 |
$containers[] = $form_state['values']['tid'];
|
| 71 |
variable_set('weblinks_containers', $containers);
|
| 72 |
drupal_set_message(t('Created new %type %term.', array('%term' => $form_state['values']['name'], '%type' => $type)));
|
| 73 |
break;
|
| 74 |
case SAVED_UPDATED:
|
| 75 |
drupal_set_message(t('The %type %term has been updated.', array('%term' => $form_state['values']['name'], '%type' => $type)));
|
| 76 |
break;
|
| 77 |
case SAVED_DELETED:
|
| 78 |
drupal_set_message(t('The %type %term has been deleted.', array('%term' => $form_state['values']['name'], '%type' => $type)));
|
| 79 |
break;
|
| 80 |
}
|
| 81 |
$form_state['redirect'] = 'admin/content/weblinks';
|
| 82 |
return;
|
| 83 |
}
|