Adding submit handlers in D6

  1. /**
  2.  * Implementation of hook_form_alter().
  3.  */
  4. function hs_taxonomy_form_alter(&$form, &$form_state, $form_id) {
  5.   // Add per-vocabulary settings for Hierarchical Select.
  6.   if ($form_id == 'taxonomy_form_vocabulary') {
  7.     require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
  8.     drupal_add_js(drupal_get_path('module', 'hs_taxonomy') .'/hs_taxonomy.js', 'module');
  9.  
  10.     $vid = $form['vid']['#value'];
  11.     $split = array_search('settings', array_keys($form)) + 1;
  12.     $first_part = array_slice($form, 0, $split);
  13.     $second_part = array_slice($form, $split);
  14.     $form = $first_part;
  15.  
  16.     $form['hierarchical_select_status'] = array(
  17.       '#type' => 'checkbox',
  18.       '#title' => t('Use the Hierarchical Select form element for this vocabulary.'),
  19.       '#default_value' => variable_get("taxonomy_hierarchical_select_$vid", 0),
  20.       '#description' => t(
  21.         'When checked, the %free_tagging and %multiple_values settings will
  22.        be managed by the Hierarchical Select configuration.',
  23.         array(
  24.           '%free_tagging' => t('Free tagging'),
  25.           '%multiple_values' => t('Multiple values'),
  26.         )
  27.       ),
  28.     );
  29.  
  30.     // Add the Hierarchical Select config form.
  31.     $module = 'hs_taxonomy';
  32.     $params = array(
  33.       'vid' => $vid,
  34.       'exclude_tid' => NULL,
  35.     );
  36.     $config_id = "taxonomy-$vid";
  37.     $vocabulary = taxonomy_vocabulary_load($vid);
  38.     $defaults = array(
  39.       // Enable the save_lineage setting by default if the multiple parents
  40.       // vocabulary option is enabled.
  41.       'save_lineage' => (int) ($vocabulary->hierarchy == 2),
  42.       'editability' => array(
  43.         'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($vid),
  44.       ),
  45.     );
  46.     $strings = array(
  47.       'hierarchy'   => t('vocabulary'),
  48.       'hierarchies' => t('vocabularies'),
  49.       'item'        => t('term'),
  50.       'items'       => t('terms'),
  51.       'item_type'   => t('term type'),
  52.       'entity'      => t('node'),
  53.       'entities'    => t('nodes'),
  54.     );
  55.     $max_hierarchy_depth = _hs_taxonomy_hierarchical_select_get_depth($vid);
  56.     $preview_is_required = $vocabulary->required;
  57.     $form['hierarchical_select'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
  58.  
  59.     // The forum selection requires that only the deepest term is saved!
  60.     // See http://drupal.org/node/241766#comment-808464.
  61.     if ($vid == variable_get('forum_nav_vocabulary', 0)) {
  62.       $form['hierarchical_select']['save_lineage']['#value'] = 0;
  63.       $form['hierarchical_select']['save_lineage']['#attributes'] = array('disabled' => 'disabled');
  64.       $form['hierarchical_select']['save_lineage']['#description'] .= '<br />'. t(
  65.         'This is the vocabulary that will be used for forum navigation and it
  66.        <strong>always</strong> requires the %dont_save_lineage setting to be
  67.        set!',
  68.         array('%dont_save_lineage' => t('Save only the deepest term'))
  69.       );
  70.     }
  71.  
  72.     // Add the the submit handler for the Hierarchical Select config form.
  73.     $parents = array('hierarchical_select');
  74.     $form['#submit'][] = 'hierarchical_select_common_config_form_submit';
  75.     $form['#hs_common_config_form_parents'] = $parents;
  76.  
  77.     // Add a validate callback to override the freetagging and multiple select
  78.     // settings if necessary.
  79.     $form['#validate'][] = 'hierarchical_select_taxonomy_form_vocabulary_validate';
  80.     $form['#submit'][]   = 'hierarchical_select_taxonomy_form_vocabulary_submit';
  81.  
  82.     // The original #submit callback(s) has/have to be executed afterwards.
  83.     $form['#submit'] = array_merge($form['#submit'], $second_part['#submit']);
  84.  
  85.     $form += $second_part;
  86.   }
  87. }