/[drupal]/contributions/modules/hierarchical_select/modules/hs_taxonomy.module
ViewVC logotype

Diff of /contributions/modules/hierarchical_select/modules/hs_taxonomy.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.26, Sun Nov 30 18:54:15 2008 UTC revision 1.27, Mon Dec 1 02:21:17 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: hs_taxonomy.module,v 1.25 2008/11/29 22:19:21 wimleers Exp $  // $Id: hs_taxonomy.module,v 1.26 2008/11/30 18:54:15 wimleers Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 13  Line 13 
13  /**  /**
14   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
15   */   */
16  function hs_taxonomy_form_alter($form_id, &$form) {  function hs_taxonomy_form_alter(&$form, &$form_state, $form_id) {
17    // Add per-vocabulary settings for Hierarchical Select.    // Add per-vocabulary settings for Hierarchical Select.
18    if ($form_id == 'taxonomy_form_vocabulary') {    if ($form_id == 'taxonomy_form_vocabulary') {
19      require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');      require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
# Line 62  function hs_taxonomy_form_alter($form_id Line 62  function hs_taxonomy_form_alter($form_id
62        'root_term'   => NULL,        'root_term'   => NULL,
63      );      );
64      $config_id = "taxonomy-$vid";      $config_id = "taxonomy-$vid";
65      $vocabulary = taxonomy_get_vocabulary($vid);      $vocabulary = taxonomy_vocabulary_load($vid);
66      $defaults = array(      $defaults = array(
67        // Enable the save_lineage setting by default if the multiple parents        // Enable the save_lineage setting by default if the multiple parents
68        // vocabulary option is enabled.        // vocabulary option is enabled.
# Line 99  function hs_taxonomy_form_alter($form_id Line 99  function hs_taxonomy_form_alter($form_id
99    
100      // Add the the submit handler for the Hierarchical Select config form.      // Add the the submit handler for the Hierarchical Select config form.
101      $parents = array('hierarchical_select');      $parents = array('hierarchical_select');
102      $form['#submit']['hierarchical_select_common_config_form_submit'] = array($parents);      $form['#submit'][] = 'hierarchical_select_common_config_form_submit';
103        $form['#hs_common_config_form_parents'] = $parents;
104    
105      // Add a validate callback to override the freetagging and multiple select      // Add a validate callback to override the freetagging and multiple select
106      // settings if necessary.      // settings if necessary.
107      $form['#validate']['hierarchical_select_taxonomy_form_vocabulary_validate'] = array();      $form['#validate'][] = 'hierarchical_select_taxonomy_form_vocabulary_validate';
108      $form['#submit']['hierarchical_select_taxonomy_form_vocabulary_submit'] = array();      $form['#submit'][]   = 'hierarchical_select_taxonomy_form_vocabulary_submit';
109    
110      // The original #submit callback(s) has/have to be executed afterwards.      // The original #submit callback(s) has/have to be executed afterwards.
111      $form['#submit'] = array_merge($form['#submit'], $second_part['#submit']);      $form['#submit'] = array_merge($form['#submit'], $second_part['#submit']);
# Line 141  function hs_taxonomy_form_alter($form_id Line 142  function hs_taxonomy_form_alter($form_id
142    
143    // The taxonomy term form.    // The taxonomy term form.
144    else if ($form_id == 'taxonomy_form_term') {    else if ($form_id == 'taxonomy_form_term') {
145      unset($form['parent']['#options']);      require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
146      unset($form['parent']['#theme']);  
147      $form['parent']['#type'] = 'hierarchical_select';      // Build an appropriate config, that inherits the level_labels settings
148      $form['parent']['#config'] = array(      // from the vocabulary's Hierarchical Select config.
149        'module'          => 'hs_taxonomy',      $vid = $form['#vocabulary']['vid'];
150        $vocabulary_config = hierarchical_select_common_config_get("taxonomy-$vid");
151        $config = array(
152          'module' => 'hs_taxonomy',
153          'params' => array(
154            'vid'         => $vid,
155            'exclude_tid' => $form['#term']['tid'],
156          ),
157        'enforce_deepest' => 0,        'enforce_deepest' => 0,
158        'save_lineage'    => 0,        'save_lineage'    => 0,
159          'level_labels' => $vocabulary_config['level_labels'],
160          'dropbox' => array(
161            'status'   => 1,
162          ),
163        'params' => array(        'params' => array(
164          'vid'         => $form['vid']['#value'],          'vid'         => $form['vid']['#value'],
165          'exclude_tid' => $form['tid']['#value'],          'exclude_tid' => $form['tid']['#value'],
166          'root_term'   => TRUE,          'root_term'   => TRUE,
167        ),        ),
168      );      );
169    
170        // Use Hierarchical Select for selecting the parent term(s).
171        unset($form['advanced']['parent']['#options']);
172        unset($form['advanced']['parent']['#theme']);
173        unset($form['advanced']['parent']['#size']);
174        $form['advanced']['parent']['#type'] = 'hierarchical_select';
175        $form['advanced']['parent']['#config'] = $config;
176        $form['advanced']['parent']['#config']['dropbox']['title'] = t('All parent terms');
177    
178        // Use Hierarchical Select for selecting the related term(s).
179        unset($form['advanced']['relations']['#options']);
180        unset($form['advanced']['relations']['#theme']);
181        unset($form['advanced']['relations']['#size']);
182        $form['advanced']['relations']['#type'] = 'hierarchical_select';
183        $form['advanced']['relations']['#config'] = $config;
184        $form['advanced']['relations']['#config']['dropbox']['title'] = t('All related terms');
185    
186      // When 'multiple parents' are enabled, we should support that as well!      // When 'multiple parents' are enabled, we should support that as well!
187      if ($form['parent']['#multiple']) {      if ($form['parent']['#multiple']) {
188        unset($form['parent']['#size']);        unset($form['parent']['#size']);
# Line 289  function hs_taxonomy_hierarchical_select Line 318  function hs_taxonomy_hierarchical_select
318   * Implementation of hook_hierarchical_select_create_item().   * Implementation of hook_hierarchical_select_create_item().
319   */   */
320  function hs_taxonomy_hierarchical_select_create_item($label, $parent, $params) {  function hs_taxonomy_hierarchical_select_create_item($label, $parent, $params) {
321    $form_values = array(    $form_state['values'] = array(
322      'name'   => $label,      'name'   => $label,
323      'parent' => $parent,      'parent' => $parent,
324      'vid'    => $params['vid'],      'vid'    => $params['vid'],
325    );    );
326    $status = taxonomy_save_term($form_values);    $status = taxonomy_save_term($form_state['values']);
327    
328    if ($status == SAVED_NEW) {    if ($status == SAVED_NEW) {
329      // Reset the cached tree.      // Reset the cached tree.
# Line 513  function _hs_taxonomy_token_termpath_for Line 542  function _hs_taxonomy_token_termpath_for
542  /**  /**
543   * Additional validate callback for the taxonomy_form_vocabulary form.   * Additional validate callback for the taxonomy_form_vocabulary form.
544   */   */
545  function hierarchical_select_taxonomy_form_vocabulary_validate($form_id, $form_values, $form) {  function hierarchical_select_taxonomy_form_vocabulary_validate($form, &$form_state) {
546    // If Hierarchical Select is enabled, the "multiple select" setting must be    // The "multiple select" setting doesn't exist for the forum vocabulary!
547    // managed by Hierarchical Select.    if (isset($form['multiple'])) {
   // TRICKY: the "multiple select" setting is absent for the forum vocabulary!  
   if ($form_values['hierarchical_select_status'] && isset($form['multiple'])) {  
548      // Enable Taxonomy's "multiple select" setting when:      // Enable Taxonomy's "multiple select" setting when:
549      // - Hierarchical Select's "multiple select" setting is enabled, or:      // - Hierarchical Select's "multiple select" setting is enabled, or:
550      // - Hierarchical Select's "save term lineage" setting is enabled      // - Hierarchical Select's "save term lineage" setting is enabled
551      $multiple_select_enabled = ($form_values['hierarchical_select']['dropbox']['status'] || $form_values['hierarchical_select']['save_lineage']);      $multiple_select_enabled = ($form_state['values']['hierarchical_select']['dropbox']['status'] || $form_state['values']['hierarchical_select']['save_lineage']);
552      form_set_value($form['multiple'], (int) $multiple_select_enabled);      form_set_value($form['multiple'], (int) $multiple_select_enabled, $form_state);
553    }    }
554    
555    // If Hierarchical Select is enabled, disable freetagging.    // If Hierarchical Select is enabled, disable freetagging.
556    if ($form_values['hierarchical_select']['status']) {    if ($form_state['values']['hierarchical_select']['status']) {
557      form_set_value($form['tags'], 0);      form_set_value($form['tags'], 0, $form_state);
558    }    }
559  }  }
560    
561  /**  /**
562   * Additional submit callback for the taxonomy_form_vocabulary form.   * Additional submit callback for the taxonomy_form_vocabulary form.
563   */   */
564  function hierarchical_select_taxonomy_form_vocabulary_submit($form_id, $form_values) {  function hierarchical_select_taxonomy_form_vocabulary_submit($form, &$form_state) {
565    $vid = $form_values['vid'];    $vid = $form_state['values']['vid'];
566    variable_set("taxonomy_hierarchical_select_$vid", $form_values['hierarchical_select_status']);    variable_set("taxonomy_hierarchical_select_$vid", $form_state['values']['hierarchical_select_status'], $form_state);
567  }  }
568    
569    

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.2