You are here

function hs_taxonomy_views_config_form in Hierarchical Select 5.3

Same name and namespace in other branches
  1. 6.3 modules/hs_taxonomy_views.module \hs_taxonomy_views_config_form()

Form definition; configuration form for Hierarchical Select as the widget for a Taxonomy exposed filter.

Parameters

$view_name: Name of a view. Provides necessary context.

$vid: A vocabulary id. Provides necessary context.

1 string reference to 'hs_taxonomy_views_config_form'
hs_taxonomy_views_menu in modules/hs_taxonomy_views.module
Implementation of hook_menu().

File

modules/hs_taxonomy_views.module, line 190
Implementation of the Hierarchical Select API for the Taxonomy module's Views exposed filters.

Code

function hs_taxonomy_views_config_form($view_name, $vid) {
  require_once drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';

  // Find the exposed filter, we need this to set the default value of
  // $config['dropbox']['status'].
  $view = views_get_view($view_name);
  foreach ($view->exposed_filter as $filter) {
    if ($filter['id'] == "term_node_{$vid}.tid") {
      $exposed_filter = $filter;
      break;
    }
  }

  // Add the Hierarchical Select config form.
  $module = 'hs_taxonomy_views';
  $params = array(
    'optional' => (bool) $view->exposed_filter[$id]['optional'],
    'vid' => $vid,
    'exclude_tid' => NULL,
    'root_term' => NULL,
  );
  $config_id = "taxonomy-views-{$view_name}-{$vid}";
  $vocabulary = taxonomy_get_vocabulary($vid);
  $defaults = array(
    // Enable the save_lineage setting by default if the multiple parents
    // vocabulary option is enabled.
    'save_lineage' => (int) ($vocabulary->hierarchy == 2),
    'dropbox' => array(
      'status' => !$exposed_filter['single'],
    ),
    'editability' => array(
      'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($vid),
    ),
  );
  $strings = array(
    'hierarchy' => t('vocabulary'),
    'hierarchies' => t('vocabularies'),
    'item' => t('term'),
    'items' => t('terms'),
    'item_type' => t('term type'),
    'entity' => t('node'),
    'entities' => t('nodes'),
  );
  $max_hierarchy_depth = _hs_taxonomy_hierarchical_select_get_depth($vid);
  $preview_is_required = !(bool) $exposed_filter['optional'];
  $form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
  $form['hierarchical_select_config']['save_lineage']['#description'] .= '<br />' . t('When you enable the %save_lineage setting, you will have to resave the
    "Edit view" form as well!', array(
    '%save_lineage' => $form['hierarchical_select_config']['save_lineage']['#options'][1],
  ));
  $form['link'] = array(
    '#value' => l('Back to the view configuration', "admin/build/views/{$view_name}/edit"),
    '#prefix' => '<div class="hierarchical-select-config-back-link">',
    '#suffix' => '</div>',
    '#weight' => -5,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  // Add the the submit handler for the Hierarchical Select config form.
  $parents = array(
    'hierarchical_select_config',
  );
  $form['#submit']['hierarchical_select_common_config_form_submit'] = array(
    $parents,
  );
  $form['#submit']['hs_taxonomy_views_common_config_form_submit'] = array(
    $view_name,
    $vid,
  );
  return $form;
}