00001 <?php
00002
00003
00016 function taxonomy_overview_vocabularies() {
00017 $vocabularies = taxonomy_get_vocabularies();
00018 $form = array('#tree' => TRUE);
00019 foreach ($vocabularies as $vocabulary) {
00020 $types = array();
00021 foreach ($vocabulary->nodes as $type) {
00022 $node_type = node_get_types('name', $type);
00023 $types[] = $node_type ? check_plain($node_type) : check_plain($type);
00024 }
00025 $form[$vocabulary->vid]['#vocabulary'] = (array)$vocabulary;
00026 $form[$vocabulary->vid]['name'] = array('#value' => check_plain($vocabulary->name));
00027 $form[$vocabulary->vid]['types'] = array('#value' => implode(', ', $types));
00028 $form[$vocabulary->vid]['weight'] = array('#type' => 'weight', '#delta' => 10, '#default_value' => $vocabulary->weight);
00029 $form[$vocabulary->vid]['edit'] = array('#value' => l(t('edit vocabulary'), "admin/content/taxonomy/edit/vocabulary/$vocabulary->vid"));
00030 $form[$vocabulary->vid]['list'] = array('#value' => l(t('list terms'), "admin/content/taxonomy/$vocabulary->vid"));
00031 $form[$vocabulary->vid]['add'] = array('#value' => l(t('add terms'), "admin/content/taxonomy/$vocabulary->vid/add/term"));
00032 }
00033
00034
00035
00036 if (count($vocabularies) > 1) {
00037 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
00038 }
00039 elseif (isset($vocabulary)) {
00040 unset($form[$vocabulary->vid]['weight']);
00041 }
00042 return $form;
00043 }
00044
00050 function taxonomy_overview_vocabularies_submit($form, &$form_state) {
00051 foreach ($form_state['values'] as $vid => $vocabulary) {
00052 if (is_numeric($vid) && $form[$vid]['#vocabulary']['weight'] != $form_state['values'][$vid]['weight']) {
00053 $form[$vid]['#vocabulary']['weight'] = $form_state['values'][$vid]['weight'];
00054 taxonomy_save_vocabulary($form[$vid]['#vocabulary']);
00055 }
00056 }
00057 }
00058
00065 function theme_taxonomy_overview_vocabularies($form) {
00066 $rows = array();
00067 foreach (element_children($form) as $key) {
00068 if (isset($form[$key]['name'])) {
00069 $vocabulary = &$form[$key];
00070
00071 $row = array();
00072 $row[] = drupal_render($vocabulary['name']);
00073 $row[] = drupal_render($vocabulary['types']);
00074 if (isset($vocabulary['weight'])) {
00075 $vocabulary['weight']['#attributes']['class'] = 'vocabulary-weight';
00076 $row[] = drupal_render($vocabulary['weight']);
00077 }
00078 $row[] = drupal_render($vocabulary['edit']);
00079 $row[] = drupal_render($vocabulary['list']);
00080 $row[] = drupal_render($vocabulary['add']);
00081 $rows[] = array('data' => $row, 'class' => 'draggable');
00082 }
00083 }
00084 if (empty($rows)) {
00085 $rows[] = array(array('data' => t('No vocabularies available.'), 'colspan' => '5'));
00086 }
00087
00088 $header = array(t('Name'), t('Type'));
00089 if (isset($form['submit'])) {
00090 $header[] = t('Weight');
00091 drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'vocabulary-weight');
00092 }
00093 $header[] = array('data' => t('Operations'), 'colspan' => '3');
00094 return theme('table', $header, $rows, array('id' => 'taxonomy')) . drupal_render($form);
00095 }
00096
00103 function taxonomy_form_vocabulary(&$form_state, $edit = array()) {
00104 $edit += array(
00105 'name' => '',
00106 'description' => '',
00107 'help' => '',
00108 'nodes' => array(),
00109 'hierarchy' => 0,
00110 'relations' => 0,
00111 'tags' => 0,
00112 'multiple' => 0,
00113 'required' => 0,
00114 'weight' => 0,
00115 );
00116
00117 if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) {
00118 return taxonomy_vocabulary_confirm_delete($form_state, $form_state['values']['vid']);
00119 }
00120 $form['identification'] = array(
00121 '#type' => 'fieldset',
00122 '#title' => t('Identification'),
00123 '#collapsible' => TRUE,
00124 );
00125 $form['identification']['name'] = array('#type' => 'textfield',
00126 '#title' => t('Vocabulary name'),
00127 '#default_value' => $edit['name'],
00128 '#maxlength' => 255,
00129 '#description' => t('The name for this vocabulary, e.g., <em>"Tags"</em>.'),
00130 '#required' => TRUE,
00131 );
00132 $form['identification']['description'] = array('#type' => 'textarea',
00133 '#title' => t('Description'),
00134 '#default_value' => $edit['description'],
00135 '#description' => t('Description of the vocabulary; can be used by modules.'),
00136 );
00137 $form['identification']['help'] = array('#type' => 'textfield',
00138 '#title' => t('Help text'),
00139 '#maxlength' => 255,
00140 '#default_value' => $edit['help'],
00141 '#description' => t('Instructions to present to the user when selecting terms, e.g., <em>"Enter a comma separated list of words"</em>.'),
00142 );
00143 $form['content_types'] = array(
00144 '#type' => 'fieldset',
00145 '#title' => t('Content types'),
00146 '#collapsible' => TRUE,
00147 );
00148 $form['content_types']['nodes'] = array('#type' => 'checkboxes',
00149 '#title' => t('Content types'),
00150 '#default_value' => $edit['nodes'],
00151 '#options' => array_map('check_plain', node_get_types('names')),
00152 '#description' => t('Select content types to categorize using this vocabulary.'),
00153 );
00154 $form['settings'] = array(
00155 '#type' => 'fieldset',
00156 '#title' => t('Settings'),
00157 '#collapsible' => TRUE,
00158 );
00159 $form['settings']['tags'] = array('#type' => 'checkbox',
00160 '#title' => t('Tags'),
00161 '#default_value' => $edit['tags'],
00162 '#description' => t('Terms are created by users when submitting posts by typing a comma separated list.'),
00163 );
00164 $form['settings']['multiple'] = array('#type' => 'checkbox',
00165 '#title' => t('Multiple select'),
00166 '#default_value' => $edit['multiple'],
00167 '#description' => t('Allows posts to have more than one term from this vocabulary (always true for tags).'),
00168 );
00169 $form['settings']['required'] = array('#type' => 'checkbox',
00170 '#title' => t('Required'),
00171 '#default_value' => $edit['required'],
00172 '#description' => t('At least one term in this vocabulary must be selected when submitting a post.'),
00173 );
00174 $form['settings']['weight'] = array('#type' => 'weight',
00175 '#title' => t('Weight'),
00176 '#default_value' => $edit['weight'],
00177 '#description' => t('Vocabularies are displayed in ascending order by weight.'),
00178 );
00179
00180
00181 $form['hierarchy'] = array('#type' => 'value',
00182 '#value' => '0',
00183 );
00184
00185 $form['relations'] = array('#type' => 'value',
00186 '#value' => '1',
00187 );
00188
00189 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
00190 if (isset($edit['vid'])) {
00191 $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
00192 $form['vid'] = array('#type' => 'value', '#value' => $edit['vid']);
00193 $form['module'] = array('#type' => 'value', '#value' => $edit['module']);
00194 }
00195 return $form;
00196 }
00197
00201 function taxonomy_form_vocabulary_submit($form, &$form_state) {
00202 if ($form_state['clicked_button']['#value'] == t('Delete')) {
00203
00204 $form_state['rebuild'] = TRUE;
00205 $form_state['confirm_delete'] = TRUE;
00206 return;
00207 }
00208
00209 $form_state['values']['nodes'] = array_filter($form_state['values']['nodes']);
00210 switch (taxonomy_save_vocabulary($form_state['values'])) {
00211 case SAVED_NEW:
00212 drupal_set_message(t('Created new vocabulary %name.', array('%name' => $form_state['values']['name'])));
00213 watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/vocabulary/' . $form_state['values']['vid']));
00214 break;
00215 case SAVED_UPDATED:
00216 drupal_set_message(t('Updated vocabulary %name.', array('%name' => $form_state['values']['name'])));
00217 watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/vocabulary/' . $form_state['values']['vid']));
00218 break;
00219 }
00220
00221 $form_state['vid'] = $form_state['values']['vid'];
00222 $form_state['redirect'] = 'admin/content/taxonomy';
00223 return;
00224 }
00225
00229 function taxonomy_admin_vocabulary_edit($vocabulary) {
00230 return drupal_get_form('taxonomy_form_vocabulary', (array)$vocabulary);
00231 }
00232
00236 function taxonomy_admin_term_edit($tid) {
00237 if ($term = (array)taxonomy_get_term($tid)) {
00238 return drupal_get_form('taxonomy_form_term', taxonomy_vocabulary_load($term['vid']), $term);
00239 }
00240 return drupal_not_found();
00241 }
00242
00253 function taxonomy_overview_terms(&$form_state, $vocabulary) {
00254 global $pager_page_array, $pager_total, $pager_total_items;
00255
00256
00257 if (isset($form_state['confirm_reset_alphabetical'])) {
00258 return taxonomy_vocabulary_confirm_reset_alphabetical($form_state, $vocabulary->vid);
00259 }
00260
00261 drupal_set_title(t('Terms in %vocabulary', array('%vocabulary' => $vocabulary->name)));
00262 $form = array(
00263 '#vocabulary' => (array)$vocabulary,
00264 '#tree' => TRUE,
00265 '#parent_fields' => FALSE,
00266 );
00267
00268 $page = isset($_GET['page']) ? $_GET['page'] : 0;
00269 $page_increment = 10;
00270 $page_entries = 0;
00271 $before_entries = 0;
00272 $after_entries = 0;
00273 $root_entries = 0;
00274
00275
00276
00277
00278 $back_peddle = NULL;
00279 $forward_peddle = 0;
00280
00281
00282 $current_page = array();
00283
00284
00285 if ($vocabulary->tags) {
00286
00287
00288 $results = pager_query(db_rewrite_sql('SELECT t.*, h.parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $page_increment, 0, NULL, $vocabulary->vid);
00289 $total_entries = db_query(db_rewrite_sql('SELECT count(*) FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d'), $page_increment, 0, NULL, $vocabulary->vid);
00290 while ($term = db_fetch_object($results)) {
00291 $key = 'tid:' . $term->tid . ':0';
00292 $current_page[$key] = $term;
00293 $page_entries++;
00294 }
00295 }
00296
00297 else {
00298 $term_deltas = array();
00299 $tree = taxonomy_get_tree($vocabulary->vid);
00300 $term = current($tree);
00301 do {
00302
00303 if (empty($term)) {
00304 break;
00305 }
00306
00307 if ($page && ($page * $page_increment) > $before_entries && !isset($back_peddle)) {
00308 $before_entries++;
00309 continue;
00310 }
00311
00312 elseif ($page_entries > $page_increment && isset($complete_tree)) {
00313 $after_entries++;
00314 continue;
00315 }
00316
00317
00318 if (isset($term->depth) && ($term->depth > 0) && !isset($back_peddle)) {
00319 $back_peddle = 0;
00320 while ($pterm = prev($tree)) {
00321 $before_entries--;
00322 $back_peddle++;
00323 if ($pterm->depth == 0) {
00324 prev($tree);
00325 continue 2;
00326 }
00327 }
00328 }
00329 $back_peddle = isset($back_peddle) ? $back_peddle : 0;
00330
00331
00332 if ($page_entries >= $page_increment + $back_peddle + 1 && $term->depth == 0 && $root_entries > 1) {
00333 $complete_tree = TRUE;
00334
00335 $after_entries++;
00336 continue;
00337 }
00338 if ($page_entries >= $page_increment + $back_peddle) {
00339 $forward_peddle++;
00340 }
00341
00342
00343 $page_entries++;
00344 $term_deltas[$term->tid] = isset($term_deltas[$term->tid]) ? $term_deltas[$term->tid] + 1 : 0;
00345 $key = 'tid:' . $term->tid . ':' . $term_deltas[$term->tid];
00346
00347
00348 if ($page_entries == 1) {
00349 $form['#first_tid'] = $term->tid;
00350 }
00351
00352 if ($term->parents[0] == 0) {
00353 $root_entries++;
00354 }
00355 $current_page[$key] = $term;
00356 } while ($term = next($tree));
00357
00358
00359 $total_entries = $before_entries + $page_entries + $after_entries;
00360 $pager_total_items[0] = $total_entries;
00361 $pager_page_array[0] = $page;
00362 $pager_total[0] = ceil($total_entries / $page_increment);
00363 }
00364
00365
00366
00367 if (!empty($form_state['post'])) {
00368 $order = array_flip(array_keys($form_state['post']));
00369 $current_page = array_merge($order, $current_page);
00370 foreach ($current_page as $key => $term) {
00371
00372 if (is_array($form_state['post'][$key]) && is_numeric($form_state['post'][$key]['tid'])) {
00373 $current_page[$key]->depth = $form_state['post'][$key]['depth'];
00374 }
00375 else {
00376 unset($current_page[$key]);
00377 }
00378 }
00379 }
00380
00381
00382 foreach ($current_page as $key => $term) {
00383
00384 $form[$key]['#term'] = (array)$term;
00385 if (isset($term->parents)) {
00386 $form[$key]['#term']['parent'] = $term->parent = $term->parents[0];
00387 unset($form[$key]['#term']['parents'], $term->parents);
00388 }
00389
00390 $form[$key]['view'] = array('#value' => l($term->name, "taxonomy/term/$term->tid"));
00391 if (!$vocabulary->tags && $vocabulary->hierarchy < 2 && count($tree) > 1) {
00392 $form['#parent_fields'] = TRUE;
00393 $form[$key]['tid'] = array(
00394 '#type' => 'hidden',
00395 '#value' => $term->tid
00396 );
00397 $form[$key]['parent'] = array(
00398 '#type' => 'hidden',
00399
00400 '#default_value' => $term->parent,
00401 );
00402 $form[$key]['depth'] = array(
00403 '#type' => 'hidden',
00404
00405 '#default_value' => $term->depth,
00406 );
00407 }
00408 $form[$key]['edit'] = array('#value' => l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array('query' => drupal_get_destination())));
00409 }
00410
00411 $form['#total_entries'] = $total_entries;
00412 $form['#page_increment'] = $page_increment;
00413 $form['#page_entries'] = $page_entries;
00414 $form['#back_peddle'] = $back_peddle;
00415 $form['#forward_peddle'] = $forward_peddle;
00416 $form['#empty_text'] = t('No terms available.');
00417
00418 if (!$vocabulary->tags && $vocabulary->hierarchy < 2 && count($tree) > 1) {
00419 $form['submit'] = array(
00420 '#type' => 'submit',
00421 '#value' => t('Save')
00422 );
00423 $form['reset_alphabetical'] = array(
00424 '#type' => 'submit',
00425 '#value' => t('Reset to alphabetical')
00426 );
00427 $form['destination'] = array(
00428 '#type' => 'hidden',
00429 '#value' => $_GET['q'] . (isset($_GET['page']) ? '?page=' . $_GET['page'] : '')
00430 );
00431 }
00432
00433 return $form;
00434 }
00435
00451 function taxonomy_overview_terms_submit($form, &$form_state) {
00452 if ($form_state['clicked_button']['#value'] == t('Reset to alphabetical')) {
00453
00454 if ($form_state['values']['reset_alphabetical'] === TRUE) {
00455 return taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, $form_state);
00456 }
00457
00458 $form_state['rebuild'] = TRUE;
00459 $form_state['confirm_reset_alphabetical'] = TRUE;
00460 return;
00461 }
00462
00463 $order = array_flip(array_keys($form['#post']));
00464 $form_state['values'] = array_merge($order, $form_state['values']);
00465
00466 $vocabulary = $form['#vocabulary'];
00467 $hierarchy = 0;
00468
00469 $changed_terms = array();
00470 $tree = taxonomy_get_tree($vocabulary['vid']);
00471
00472 if (empty($tree)) {
00473 return;
00474 }
00475
00476
00477 $weight = 0;
00478 $term = (array)$tree[0];
00479 while ($term['tid'] != $form['#first_tid']) {
00480 if ($term['parents'][0] == 0 && $term['weight'] != $weight) {
00481 $term['parent'] = $term['parents'][0];
00482 $term['weight'] = $weight;
00483 $changed_terms[$term['tid']] = $term;
00484 }
00485 $weight++;
00486 $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;
00487 $term = (array)$tree[$weight];
00488 }
00489
00490
00491 $level_weights = array();
00492 foreach ($form_state['values'] as $tid => $values) {
00493 if (isset($form[$tid]['#term'])) {
00494 $term = $form[$tid]['#term'];
00495
00496 if ($values['parent'] == 0 && $term['weight'] != $weight) {
00497 $term['weight'] = $weight;
00498 $changed_terms[$term['tid']] = $term;
00499 }
00500
00501 elseif ($values['parent'] > 0) {
00502 $level_weights[$values['parent']] = isset($level_weights[$values['parent']]) ? $level_weights[$values['parent']] + 1 : 0;
00503 if ($level_weights[$values['parent']] != $term['weight']) {
00504 $term['weight'] = $level_weights[$values['parent']];
00505 $changed_terms[$term['tid']] = $term;
00506 }
00507 }
00508
00509 if ($values['parent'] != $term['parent']) {
00510 $term['parent'] = $values['parent'];
00511 $changed_terms[$term['tid']] = $term;
00512 }
00513 $hierarchy = $term['parent'] != 0 ? 1 : $hierarchy;
00514 $weight++;
00515 }
00516 }
00517
00518
00519 for ($weight; $weight < count($tree); $weight++) {
00520 $term = (array)$tree[$weight];
00521 if ($term['parents'][0] == 0 && $term['weight'] != $weight) {
00522 $term['parent'] = $term['parents'][0];
00523 $term['weight'] = $weight;
00524 $changed_terms[$term['tid']] = $term;
00525 }
00526 $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;
00527 }
00528
00529
00530 foreach ($changed_terms as $term) {
00531 taxonomy_save_term($term);
00532 }
00533
00534
00535 if ($vocabulary['hierarchy'] != $hierarchy) {
00536 $vocabulary['hierarchy'] = $hierarchy;
00537 taxonomy_save_vocabulary($vocabulary);
00538 }
00539 }
00540
00547 function theme_taxonomy_overview_terms($form) {
00548 $page_increment = $form['#page_increment'];
00549 $page_entries = $form['#page_entries'];
00550 $back_peddle = $form['#back_peddle'];
00551 $forward_peddle = $form['#forward_peddle'];
00552
00553
00554 if ($form['#parent_fields']) {
00555 drupal_add_tabledrag('taxonomy', 'match', 'parent', 'term-parent', 'term-parent', 'term-id', FALSE);
00556 drupal_add_tabledrag('taxonomy', 'depth', 'group', 'term-depth', NULL, NULL, FALSE);
00557 drupal_add_js(drupal_get_path('module', 'taxonomy') . '/taxonomy.js');
00558 drupal_add_js(array('taxonomy' => array('backPeddle' => $back_peddle, 'forwardPeddle' => $forward_peddle)), 'setting');
00559 drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
00560 }
00561
00562 $errors = form_get_errors() != FALSE ? form_get_errors() : array();
00563 $rows = array();
00564 foreach (element_children($form) as $key) {
00565 if (isset($form[$key]['#term'])) {
00566 $term = &$form[$key];
00567
00568 $row = array();
00569 $row[] = (isset($term['#term']['depth']) && $term['#term']['depth'] > 0 ? theme('indentation', $term['#term']['depth']) : '') . drupal_render($term['view']);
00570 if ($form['#parent_fields']) {
00571 $term['tid']['#attributes']['class'] = 'term-id';
00572 $term['parent']['#attributes']['class'] = 'term-parent';
00573 $term['depth']['#attributes']['class'] = 'term-depth';
00574 $row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']);
00575 }
00576 $row[] = drupal_render($term['edit']);
00577
00578 $row = array('data' => $row);
00579 $rows[$key] = $row;
00580 }
00581 }
00582
00583
00584 $row_position = 0;
00585 foreach ($rows as $key => $row) {
00586 $classes = array();
00587 if (isset($form['#parent_fields'])) {
00588 $classes[] = 'draggable';
00589 }
00590
00591
00592 if ($row_position < $back_peddle || $row_position >= $page_entries - $forward_peddle) {
00593 $classes[] = 'taxonomy-term-preview';
00594 }
00595
00596 if ($row_position !== 0 && $row_position !== count($rows) - 1) {
00597 if ($row_position == $back_peddle - 1 || $row_position == $page_entries - $forward_peddle - 1) {
00598 $classes[] = 'taxonomy-term-divider-top';
00599 }
00600 elseif ($row_position == $back_peddle || $row_position == $page_entries - $forward_peddle) {
00601 $classes[] = 'taxonomy-term-divider-bottom';
00602 }
00603 }
00604
00605
00606 foreach ($errors as $error_key => $error) {
00607 if (strpos($error_key, $key) === 0) {
00608 $classes[] = 'error';
00609 }
00610 }
00611 $rows[$key]['class'] = implode(' ', $classes);
00612 $row_position++;
00613 }
00614
00615 if (empty($rows)) {
00616 $rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '2'));
00617 }
00618
00619 $header = array(t('Name'), t('Operations'));
00620 $output = theme('table', $header, $rows, array('id' => 'taxonomy'));
00621 $output .= drupal_render($form);
00622 $output .= theme('pager', NULL, $page_increment);
00623
00624 return $output;
00625 }
00626
00630 function taxonomy_add_term_page($vocabulary) {
00631 drupal_set_title(t('Add term to %vocabulary', array('%vocabulary' => $vocabulary->name)));
00632 return drupal_get_form('taxonomy_form_term' , $vocabulary);
00633 }
00634
00641 function taxonomy_form_term(&$form_state, $vocabulary, $edit = array()) {
00642 $edit += array(
00643 'name' => '',
00644 'description' => '',
00645 'tid' => NULL,
00646 'weight' => 0,
00647 );
00648
00649 $parent = array_keys(taxonomy_get_parents($edit['tid']));
00650 $form['#term'] = $edit;
00651 $form['#term']['parent'] = $parent;
00652 $form['#vocabulary'] = (array)$vocabulary;
00653 $form['#vocabulary']['nodes'] = drupal_map_assoc($vocabulary->nodes);;
00654
00655
00656 if (isset($form_state['confirm_delete'])) {
00657 return array_merge($form, taxonomy_term_confirm_delete($form_state, $edit['tid']));
00658 }
00659 elseif (isset($form_state['confirm_parents'])) {
00660 return array_merge($form, taxonomy_term_confirm_parents($form_state, $vocabulary));
00661 }
00662
00663 $form['identification'] = array(
00664 '#type' => 'fieldset',
00665 '#title' => t('Identification'),
00666 '#collapsible' => TRUE,
00667 );
00668 $form['identification']['name'] = array(
00669 '#type' => 'textfield',
00670 '#title' => t('Term name'),
00671 '#default_value' => $edit['name'],
00672 '#maxlength' => 255,
00673 '#description' => t('The name of this term.'),
00674 '#required' => TRUE);
00675 $form['identification']['description'] = array(
00676 '#type' => 'textarea',
00677 '#title' => t('Description'),
00678 '#default_value' => $edit['description'],
00679 '#description' => t('A description of the term. To be displayed on taxonomy/term pages and RSS feeds.'));
00680
00681 $form['advanced'] = array(
00682 '#type' => 'fieldset',
00683 '#title' => t('Advanced options'),
00684 '#collapsible' => TRUE,
00685 '#collapsed' => $vocabulary->hierarchy > 1 ? FALSE : TRUE,
00686 );
00687
00688
00689
00690
00691
00692 if (!variable_get('taxonomy_override_selector', FALSE)) {
00693 $parent = array_keys(taxonomy_get_parents($edit['tid']));
00694 $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']);
00695
00696
00697 foreach ($children as $child) {
00698 $exclude[] = $child->tid;
00699 }
00700 $exclude[] = $edit['tid'];
00701
00702 $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') . '.', 1, '<' . t('root') . '>', $exclude);
00703 $form['advanced']['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary->vid, NULL, 1, '<' . t('none') . '>', array($edit['tid']));
00704 }
00705 $form['advanced']['synonyms'] = array(
00706 '#type' => 'textarea',
00707 '#title' => t('Synonyms'),
00708 '#default_value' => implode("\n", taxonomy_get_synonyms($edit['tid'])),
00709 '#description' => t('Synonyms of this term, one synonym per line.'));
00710 $form['advanced']['weight'] = array(
00711 '#type' => 'textfield',
00712 '#title' => t('Weight'),
00713 '#size' => 6,
00714 '#default_value' => $edit['weight'],
00715 '#description' => t('Terms are displayed in ascending order by weight.'),
00716 '#required' => TRUE);
00717 $form['vid'] = array(
00718 '#type' => 'value',
00719 '#value' => $vocabulary->vid);
00720 $form['submit'] = array(
00721 '#type' => 'submit',
00722 '#value' => t('Save'));
00723
00724 if ($edit['tid']) {
00725 $form['delete'] = array(
00726 '#type' => 'submit',
00727 '#value' => t('Delete'));
00728 $form['tid'] = array(
00729 '#type' => 'value',
00730 '#value' => $edit['tid']);
00731 }
00732 else {
00733 $form['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']);
00734 }
00735
00736 return $form;
00737 }
00738
00744 function taxonomy_form_term_validate($form, &$form_state) {
00745 if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) {
00746 form_set_error('weight', t('Weight value must be numeric.'));
00747 }
00748 }
00749
00755 function taxonomy_form_term_submit($form, &$form_state) {
00756 if ($form_state['clicked_button']['#value'] == t('Delete')) {
00757
00758 if ($form_state['values']['delete'] === TRUE) {
00759 return taxonomy_term_confirm_delete_submit($form, $form_state);
00760 }
00761
00762 $form_state['rebuild'] = TRUE;
00763 $form_state['confirm_delete'] = TRUE;
00764 return;
00765 }
00766
00767 elseif ($form_state['clicked_button']['#value'] == t('Save') && !$form['#vocabulary']['tags'] && count($form_state['values']['parent']) > 1 && $form['#vocabulary']['hierarchy'] < 2) {
00768 $form_state['rebuild'] = TRUE;
00769 $form_state['confirm_parents'] = TRUE;
00770 return;
00771 }
00772
00773 switch (taxonomy_save_term($form_state['values'])) {
00774 case SAVED_NEW:
00775 drupal_set_message(t('Created new term %term.', array('%term' => $form_state['values']['name'])));
00776 watchdog('taxonomy', 'Created new term %term.', array('%term' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/' . $form_state['values']['tid']));
00777 break;
00778 case SAVED_UPDATED:
00779 drupal_set_message(t('Updated term %term.', array('%term' => $form_state['values']['name'])));
00780 watchdog('taxonomy', 'Updated term %term.', array('%term' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/' . $form_state['values']['tid']));
00781 break;
00782 }
00783
00784 if (!$form['#vocabulary']['tags']) {
00785 $current_parent_count = count($form_state['values']['parent']);
00786 $previous_parent_count = count($form['#term']['parent']);
00787
00788 if ($current_parent_count == 1 && isset($form_state['values']['parent'][''])) {
00789 $current_parent_count = 0;
00790 $form_state['values']['parent'] = array();
00791 }
00792
00793
00794
00795 if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) {
00796 taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);
00797 }
00798
00799
00800 elseif ($current_parent_count > $previous_parent_count && $form['#vocabulary']['hierarchy'] < 2) {
00801 $form['#vocabulary']['hierarchy'] = $current_parent_count == 1 ? 1 : 2;
00802 taxonomy_save_vocabulary($form['#vocabulary']);
00803 }
00804 }
00805
00806 $form_state['tid'] = $form_state['values']['tid'];
00807 $form_state['redirect'] = 'admin/content/taxonomy';
00808 return;
00809 }
00810
00817 function taxonomy_term_confirm_parents(&$form_state, $vocabulary) {
00818 $form = array();
00819 foreach (element_children($form_state['values']) as $key) {
00820 $form[$key] = array(
00821 '#type' => 'value',
00822 '#value' => $form_state['values'][$key],
00823 );
00824 }
00825 $question = t('Set multiple term parents?');
00826 $description = '<p>' . t("Adding multiple parents to a term will cause the %vocabulary vocabulary to look for multiple parents on every term. Because multiple parents are not supported when using the drag and drop outline interface, drag and drop will be disabled if you enable this option. If you choose to have multiple parents, you will only be able to set parents by using the term edit form.", array('%vocabulary' => $vocabulary->name)) . '</p>';
00827 $description .= '<p>' . t("You may re-enable the drag and drop interface at any time by reducing multiple parents to a single parent for the terms in this vocabulary.") . '</p>';
00828 return confirm_form($form, $question, drupal_get_destination(), $description, t('Set multiple parents'));
00829 }
00830
00837 function taxonomy_term_confirm_delete(&$form_state, $tid) {
00838 $term = taxonomy_get_term($tid);
00839
00840 $form['type'] = array('#type' => 'value', '#value' => 'term');
00841 $form['name'] = array('#type' => 'value', '#value' => $term->name);
00842 $form['tid'] = array('#type' => 'value', '#value' => $tid);
00843 $form['delete'] = array('#type' => 'value', '#value' => TRUE);
00844 return confirm_form($form,
00845 t('Are you sure you want to delete the term %title?',
00846 array('%title' => $term->name)),
00847 'admin/content/taxonomy',
00848 t('Deleting a term will delete all its children if there are any. This action cannot be undone.'),
00849 t('Delete'),
00850 t('Cancel'));
00851 }
00852
00858 function taxonomy_term_confirm_delete_submit($form, &$form_state) {
00859 taxonomy_del_term($form_state['values']['tid']);
00860 taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);
00861 drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name'])));
00862 watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
00863 $form_state['redirect'] = 'admin/content/taxonomy';
00864 return;
00865 }
00866
00873 function taxonomy_vocabulary_confirm_delete(&$form_state, $vid) {
00874 $vocabulary = taxonomy_vocabulary_load($vid);
00875
00876 $form['#id'] = 'taxonomy_vocabulary_confirm_delete';
00877 $form['type'] = array('#type' => 'value', '#value' => 'vocabulary');
00878 $form['vid'] = array('#type' => 'value', '#value' => $vid);
00879 $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name);
00880 $form['#submit'] = array('taxonomy_vocabulary_confirm_delete_submit');
00881 return confirm_form($form,
00882 t('Are you sure you want to delete the vocabulary %title?',
00883 array('%title' => $vocabulary->name)),
00884 'admin/content/taxonomy',
00885 t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
00886 t('Delete'),
00887 t('Cancel'));
00888 }
00889
00895 function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) {
00896 $status = taxonomy_del_vocabulary($form_state['values']['vid']);
00897 drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name'])));
00898 watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
00899 $form_state['redirect'] = 'admin/content/taxonomy';
00900 return;
00901 }
00902
00909 function taxonomy_vocabulary_confirm_reset_alphabetical(&$form_state, $vid) {
00910 $vocabulary = taxonomy_vocabulary_load($vid);
00911
00912 $form['type'] = array('#type' => 'value', '#value' => 'vocabulary');
00913 $form['vid'] = array('#type' => 'value', '#value' => $vid);
00914 $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name);
00915 $form['reset_alphabetical'] = array('#type' => 'value', '#value' => TRUE);
00916 return confirm_form($form,
00917 t('Are you sure you want to reset the vocabulary %title to alphabetical order?',
00918 array('%title' => $vocabulary->name)),
00919 'admin/content/taxonomy/' . $vid,
00920 t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'),
00921 t('Reset to alphabetical'),
00922 t('Cancel'));
00923 }
00924
00930 function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) {
00931 db_query('UPDATE {term_data} t SET weight = 0 WHERE vid = %d', $form_state['values']['vid']);
00932 drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name'])));
00933 watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
00934 $form_state['redirect'] = 'admin/content/taxonomy/' . $form_state['values']['vid'];
00935 }