Jump to:
| Project: | Views Filter Block |
| Version: | 5.x-1.5 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi All,
I'm trying to get the hang of this whole 'theming' thing but some of the details still escape me. In this case I am trying to theme a filter block. I copied the 'theme_views_filterblock' fcn from the module and with that I've been able to change the attributes of the form fields. What I'm wondering now is how do I go about adding or subtracting HTML. For instance, I would like to remove the fieldset tags and add a div that wraps all of the filters.
Do I make these changes in template.php or do I need to create a tpl file for the specific filterblock? If the latter, where do I find the code to start with as a template?
Thanks for any and all help!
Below is my code from template.php
[code]
/*theming views filter block to change action, add inline styles, and remove collapsed classes*/
function bluemarine_views_filterblock($form) {
$view = $form['view']['#value'];
//JNM is changing the value of the hidden 'q' input field so that the form submits to the 'main' page and also puts 'main' in the url
$form['q']['#value'] = 'main';
// make the 'q' come first
$output = drupal_render($form['q']);
foreach ($view->exposed_filter as $count => $filter) {
$newform["fieldset$count"] = array(
'#action' => "/index.php?q=main",
'#type' => 'fieldset',
'#title' => $filter['label'],
//'#attributes' => array(
//'onBlur'=>'InputLengthCheck()',
//'onKeyUp'=>'InputLengthCheck()'),
'#collapsible' => true,
'#weight' => $count - 1000, // we'll never have this many filters
);
//JNM changing this line to false so default is not collapsed
$newform["fieldset$count"]['#collapsed'] = FALSE;
}
foreach ($form as $field => $value) {
if (preg_match('/(op|filter)([0-9]+)/', $field, $match)) {
$curcount = $match[2];
$newform["fieldset$curcount"][$field] = $value;
if ($newform["fieldset$curcount"][$field]['#value'] == '') {
unset($newform["fieldset$curcount"][$field]['#value']);
}
if (!isset($newform["fieldset$curcount"]['#weight'])) {
$newform["fieldset$curcount"]['#weight'] = $value['#weight'];
}
}
else {
if ($field == 'submit' || drupal_substr($field, 0, 1) == '#') {
unset($curcount);
}
if (isset($curcount)) {
$newform["fieldset$curcount"][$field] = $value;
}
else {
$newform[$field] = $value;
}
}
}
foreach ($view->exposed_filter as $count => $filter) {
if ($filter['is_default']) {
$newform["fieldset$count"]['#collapsed'] = FALSE;
$open = TRUE;
}
else {
$value = $newform["fieldset$count"]["filter$count"]['#default_value'];
if (isset($value)) {
if (is_array($value)) {
foreach ($value as $key => $item) {
if ($item != '') {
$newform["fieldset$count"]['#collapsed'] = FALSE;
$open = TRUE;
}
}
}
elseif ($value != '') {
$newform["fieldset$count"]['#collapsed'] = FALSE;
$open = TRUE;
}
}
}
}
if (!$open) {
$newform["fieldset0"]['#collapsed'] = FALSE;
}
//dprint_r($form);
return $output . theme('views_filterblock_output', $newform);
}
[/code]
Comments
#1
Subscribe
collapsible/collapsed fieldsets should be removed
#2
http://drupal.org/sandbox/the_g_bomb/1169958