function hs_taxonomy_views_handler_filter_term_node_tid::value_form in Hierarchical Select 6.3
File
- modules/
hs_taxonomy_views_handler_filter_term_node_tid.inc, line 33 - This file defines a new filter handler for using Hierarchical Select in exposed Taxonomy term filters.
Class
- hs_taxonomy_views_handler_filter_term_node_tid
- @file This file defines a new filter handler for using Hierarchical Select in exposed Taxonomy term filters.
Code
function value_form(&$form, &$form_state) {
// Support limiting of vocabulary by the vocabulary's module name (this is
// possible when a vocabulary is exported/defined as a feature, see
// http://drupal.org/node/789556) or by the vocabulary's vid.
if (isset($this->options['limit_by']) && $this->options['limit_by'] == 'module') {
foreach (taxonomy_get_vocabularies() as $vid => $vocab) {
if ($vocab->module == $this->options['module']) {
$vocabulary = $vocab;
break;
}
}
}
else {
$vocabulary = taxonomy_vocabulary_load($this->options['vid']);
}
$view_name = $this->view->name;
$filter_id = $this->options['id'];
$display_id = _hs_taxonomy_views_get_display_id_for_filter($this->view, $filter_id);
$optional = $this->options['expose']['optional'];
$config_id = "taxonomy-views-{$view_name}-{$display_id}-{$filter_id}";
// When not exposed: settings form.
if (empty($form_state['exposed'])) {
// When the 'Selection type' is 'Hierarchical Select', user our own
// value_form, otherwise use the parent's class form.
if ($this->options['type'] == 'textfield' || $this->options['type'] == 'select') {
parent::value_form($form, $form_state);
}
else {
$config = hierarchical_select_common_config_get($config_id);
$form['value'] = array(
'#type' => 'hierarchical_select',
'#title' => t('Select terms from vocabulary @voc', array(
'@voc' => $vocabulary->name,
)),
'#default_value' => !empty($this->value) ? $this->value : array(),
'#config' => array(
'module' => 'hs_taxonomy',
'params' => array(
'vid' => $vocabulary->vid,
'exclude_tid' => NULL,
'root_term' => NULL,
),
'save_lineage' => $config['save_lineage'],
'enforce_deepest' => $config['enforce_deepest'],
'entity_count' => $config['entity_count'],
'resizable' => 1,
'level_labels' => array(
'status' => $config['level_labels']['status'],
'labels' => $config['level_labels']['labels'],
),
'dropbox' => array(
'status' => $config['dropbox']['status'],
'title' => t('Terms to filter by'),
'limit' => $config['dropbox']['limit'],
'reset_hs' => $config['dropbox']['reset_hs'],
),
// Use our custom callback, because this is part of
// views_ui_config_item_form(), which requires access to the
// $view object, which will be restored automatically through
// this special menu callback.
'path' => "hs_taxonomy_views_json/{$view_name}/{$display_id}",
),
);
}
}
else {
// When the 'Selection type' is 'Hierarchical Select', user our own
// value_form, otherwise use the parent's class form.
if (!$this
->select_type_is_hierarchical_select()) {
parent::value_form($form, $form_state);
}
else {
$default_value = isset($this->value) && !empty($this->value) ? $this->value : array();
// Basic settings for the form item.
$form['value']['#type'] = 'hierarchical_select';
$form['value']['#default_value'] = $default_value;
$form['value']['#required'] = !(bool) $optional;
// Apply the Hierarchical Select configuration to the form item.
$defaults_override = array(
'module' => 'hs_taxonomy_views',
'params' => array(
'optional' => (bool) $optional,
'filter_id' => $filter_id,
'vid' => $vocabulary->vid,
'exclude_tid' => NULL,
'root_term' => NULL,
),
// 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',
),
),
// This is a GET form, so also render the flat select.
'render_flat_select' => 1,
// Use our custom callback.
'path' => "hs_taxonomy_views_json/{$view_name}/{$display_id}",
);
hierarchical_select_common_config_apply($form['value'], $config_id, $defaults_override);
}
}
}