You are here

function hs_taxonomy_views_config_form in Hierarchical Select 6.3

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

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

Parameters

$view: A view object.

$display_id: The ID of a display within the given view object.

$filter_id: The ID of a filter used within the given view object.

1 string reference to 'hs_taxonomy_views_config_form'
hs_taxonomy_views_config in modules/hs_taxonomy_views.module
Menu callback; Hierarchical Select configuration form page.

File

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

Code

function hs_taxonomy_views_config_form($form_state, $view, $display_id, $filter_id) {
  require_once drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';
  $filter = _hs_taxonomy_views_get_filter($view, $display_id, $filter_id);

  // Build the config ID.
  $config_id = "taxonomy-views-{$view->name}-{$display_id}-{$filter_id}";

  // Add the Hierarchical Select config form.
  $module = 'hs_taxonomy_views';
  $params = array(
    'optional' => (bool) $filter['expose']['optional'],
    'filter_id' => $filter_id,
    'vid' => $filter['vid'],
    'exclude_tid' => NULL,
    'root_term' => NULL,
  );
  $vocabulary = taxonomy_vocabulary_load($params['vid']);
  $defaults = array(
    // Enable the save_lineage setting by default if the multiple parents
    // vocabulary option is enabled.
    'save_lineage' => (int) ($vocabulary->hierarchy == 2),
    'editability' => array(
      'max_levels' => _hs_taxonomy_hierarchical_select_get_depth($filter['vid']),
    ),
    // Use our custom callback.
    'path' => "hs_taxonomy_views_json/{$view->name}/{$display_id}",
    // When the 'Any' option is selected, nothing else should be and it
    // should replace the '<none>' option.
    'special_items' => array(
      HS_TAXONOMY_VIEWS_ANY_OPTION => array(
        'none',
        'exclusive',
      ),
    ),
  );
  $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($vocabulary->vid);
  $preview_is_required = !(bool) $filter['expose']['optional'];
  $form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
  $form['link'] = array(
    '#value' => l("Back to the View's display configuration", "admin/build/views/edit/{$view->name}", array(
      'fragment' => 'views-tab-' . $display_id,
    )),
    '#prefix' => '<div class="hierarchical-select-config-back-link">',
    '#suffix' => '</div>',
    '#weight' => -5,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  // Add the custom submit handler for the Hierarchical Select config form
  // that will update the View object when necessary.
  $form['#submit'][] = 'hs_taxonomy_views_common_config_form_submit';
  $form['#custom_submit_data'] = array(
    'view_name' => $view->name,
    'display_id' => $display_id,
    'filter_id' => $filter_id,
  );

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