function tripal_views_handler_filter_select_string::value_form
2.x tripal_views_handler_filter_select_string.inc | tripal_views_handler_filter_select_string::value_form(&$form, &$form_state) |
3.x tripal_views_handler_filter_select_string.inc | tripal_views_handler_filter_select_string::value_form(&$form, &$form_state) |
1.x tripal_views_handler_filter_select_string.inc | tripal_views_handler_filter_select_string::value_form(&$form, &$form_state) |
Defines the value field in both the views filter options form and the exposed form
Overrides views_handler_filter_string::value_form
1 call to tripal_views_handler_filter_select_string::value_form()
- tripal_views_handler_filter_select_string::exposed_form in tripal_views/
views/ handlers/ tripal_views_handler_filter_select_string.inc - Ensures the select list gets rendered when the filter is exposed
File
- tripal_views/
views/ handlers/ tripal_views_handler_filter_select_string.inc, line 60 - Purpose: This Handler provides a generic select list for any chado field that is a string The select list includes all distinct values for that field.
Class
- tripal_views_handler_filter_select_string
- @file Purpose: This Handler provides a generic select list for any chado field that is a string The select list includes all distinct values for that field.
Code
function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state);
if (preg_match('/textfield/', $this->options['values_form_type'])) {
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('%label', array('%label' => $this->options['label'])),
'#default_value' => $this->value,
);
}
else {
// build a where clause that will filter the list in the drop box
// using fields that are not exposed and that are for the table
// from whcih the values in the drop box will be slected and
// we only want to use non-exposed fields because these are not
// available to the user to edit--they're fixed.
$where = '';
$filters = (is_array($this->view->filter)) ? $this->view->filter : array();
foreach ($filters as $filter_name => $details) {
// we only want to inclue non-exposed filters
if ($details->options['exposed'] == FALSE) {
// we only want to filter on the table we're getting the list from
if (strcmp($details->table, $this->table) == 0) {
$where .= "$details->field $details->operator " . $details->value['value'];
$where .= ' AND ';
}
}
}
if ($where) {
$where = "WHERE $where";
$where = substr($where, 0, -5); # remove the final ' AND '
}
// get the values from the table
$sql = "SELECT $this->real_field FROM {$this->table} $where ORDER BY $this->field ASC";
$results = chado_query($sql);
// Build the select box options
$max_length = $this->options['max_length'];
if (!$max_length) {
$max_length = 40;
}
$options = array();
if ($this->options['optional']) {
//$options['<select '.$this->table.'>'] = '--None--';
$options['All'] = '--Any--';
}
while ($r = db_fetch_object($results)) {
if (drupal_strlen($r->{$this->field}) > $max_length) {
$options[$r->{$this->field}] = drupal_substr($r->{$this->field}, 0, $max_length) . '...';
}
else {
$options[$r->{$this->field}] = $r->{$this->field};
}
}
//Select List
$form['value'] = array(
'#type' => 'select',
'#title' => t('%label', array('%label' => $this->options['label'])),
'#options' => $options,
'#default_value' => $this->value,
);
if ($this->options['multiple']) {
$form['value']['#multiple'] = TRUE;
}
}
}