diff -urp views_filterblock/README.txt filterblock/README.txt --- views_filterblock/README.txt 2006-12-04 16:03:21.000000000 -0700 +++ filterblock/README.txt 2008-09-11 21:36:35.000000000 -0600 @@ -1,27 +1,25 @@ -/* $Id: README.txt,v 1.5 2006/12/04 23:03:21 douggreen Exp $ +/* $Id$ + +The views_filterblock module duplicates the Views2 exposed filters to a block. +It does not theme the output, as the theme is inherited from Views2. -The views_filterblock module basically moves the horizontal filter from the -views page content area into a (vertical) block. This differs from the views -block option which displays the view exposed filters AND a limited number of -rows from views content. It themes the block using collapsible fieldsets -rather than the table currently used by views, and it uses some logic to -decide which fieldsets should be collapsed or not collapsed based on whether -the filter form has a value. Installation ------------ 1. Install this file into the modules directory of your choice (for example, -sites/yoursite.com/modules/views_filterblock or modules/views_filterblock). -2. Enable the module in the admin/modules page -3. Optionally set the number of blocks you need in -admin/settings/views_filterblock. -3. Add the 'Views Filter Form' blocks on the admin/block page and configure +sites/all/modules/views_filterblock). +2. Enable the module in the admin/build/modules page +3. Optionally set the number of blocks you need in admin/settings/views_filterblock +and whether you want the form hidden on page. +4. Add the 'Views Filter Form' blocks on the admin/build/block page and configure them. You may want to restrict this block to only display on your views page by using the block configure options, but this is not a requirement. -Author +Original Author ------ Doug Green doug@civicactions.net douggreen@douggreenconsulting.com + +patched to Drupal 6 and Views2 by CrashTest_ (Pat Teglia) Only in filterblock: views-filterblock.css diff -urp views_filterblock/views_filterblock.info filterblock/views_filterblock.info --- views_filterblock/views_filterblock.info 2008-02-19 06:50:13.000000000 -0700 +++ filterblock/views_filterblock.info 2008-09-11 21:36:36.000000000 -0600 @@ -1,11 +1,6 @@ -; $Id: views_filterblock.info,v 1.1.2.3 2007/08/07 13:15:27 douggreen Exp $ +; $Id$ name = Views FilterBlock -description = Move the views filter form to a block. -dependencies = views +description = Enable display of Views2 exposed filters as a block. +dependencies[] = views package = "Views" - -; Information added by drupal.org packaging script on 2008-02-19 -version = "5.x-1.4" -project = "views_filterblock" -datestamp = "1203429013" - +core = 6.x \ No newline at end of file diff -urp views_filterblock/views_filterblock.install filterblock/views_filterblock.install --- views_filterblock/views_filterblock.install 2008-01-22 09:53:59.000000000 -0700 +++ filterblock/views_filterblock.install 2008-09-11 21:36:36.000000000 -0600 @@ -1,24 +1,25 @@ $value) { - if (substr($key, 0, $len) == $prefix) { + if (drupal_substr($key, 0, $len) == $prefix) { variable_del($key); } } } /** - * Implementation of hook_uninstall + * Implementation of hook_uninstall(). */ function views_filterblock_uninstall() { _views_filterblock_variable_delete_prefix('views_filterblock_view.'); variable_del('views_filterblock_num'); + variable_del('views_filterblock_hide'); } diff -urp views_filterblock/views_filterblock.module filterblock/views_filterblock.module --- views_filterblock/views_filterblock.module 2008-02-16 19:55:28.000000000 -0700 +++ filterblock/views_filterblock.module 2008-09-11 21:53:30.000000000 -0600 @@ -1,31 +1,26 @@ 'admin/settings/views_filterblock', - 'title' => t('Views Filter Block'), - 'description' => t('Move the views filter form to a block.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'views_filterblock_settings', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, // optional - ); - } +function views_filterblock_menu() { + $items['admin/settings/views_filterblock'] = array( + 'title' => 'Views2 Filter Block', + 'description' => 'Configure Views2 filterblocks.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_filterblock_settings'), + 'access arguments' => array('administer views_filterblock'), + ); return $items; } +/** + * Set up the settings page. + */ function views_filterblock_settings() { $form['views_filterblock_num'] = array( '#type' => 'select', @@ -34,6 +29,11 @@ function views_filterblock_settings() { '#default_value' => variable_get('views_filterblock_num', 1), '#description' => t('Select the number of blocks'), ); + $form['views_filterblock_hide'] = array( + '#type' => 'checkbox', + '#title' => t('Hide Page View Form'), + '#description' => t('Select this to hide the same form on the page view.'), + ); return system_settings_form($form); } @@ -41,158 +41,93 @@ function views_filterblock_settings() { * Implementation of hook_block(). */ function views_filterblock_block($op = 'list', $delta = 0, $edit = array() ) { - if ($op == 'list') { - for ($i = 0; $i < variable_get('views_filterblock_num', 1); $i ++) { - $blocks[$i]['info'] = t('Views Filter Block.!i', array('!i' => $i)); - } - return $blocks; - } - elseif ($op == 'configure') { - $options[''] = '-- Select One --'; - $result = db_query('SELECT * FROM {view_view} WHERE page=1'); - while ($view = db_fetch_object($result)) { - $options[$view->name] = $view->description ? $view->description : $view->name; - $used[$view->name] = true; - } - $default_views = _views_get_default_views(); - foreach ($default_views as $name => $view) { - if ($view->page && !$used[$view->name]) { - $options[$view->name] = $view->description; - } - } - asort($options); - - $var = 'views_filterblock_view'; - $form[$var] = array( - '#type' => 'select', - '#title' => t('View'), - '#options' => $options, - '#default_value' => variable_get("$var.$delta", ''), - '#description' => t('Select a View whose filter you want to display in the block'), - ); - return $form; - } - elseif ($op == 'save') { - $var = 'views_filterblock_view'; - variable_set("$var.$delta", $edit[$var]); - } - elseif ($op == 'view') { - $block['content'] = _views_filterblock_block($delta); - return $block; - } -} - -function _views_filterblock_block($delta) { - // TODO: this needs to be rewritten for Drupal 5.0 - if ($name = variable_get("views_filterblock_view.$delta", '')) { - if ($view = views_get_view($name)) { - return drupal_get_form('views_filterblock', $view); - } - } -} - -function views_filterblock($view) { - $form = views_filters($view); - $form['#action'] = url($view->url); - $form['#views_filterblock'] = true; - return $form; -} - -function theme_views_filterblock($form) { - $view = $form['view']['#value']; - - // make the 'q' come first - $output = drupal_render($form['q']); - - foreach ($view->exposed_filter as $count => $filter) { - $newform["fieldset$count"] = array( - '#type' => 'fieldset', - '#title' => $filter['label'], - '#collapsible' => true, - '#weight' => $count - 1000, // we'll never have this many filters - ); - $newform["fieldset$count"]['#collapsed'] = TRUE; - } + switch ($op) { - 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; + case 'list': + for ($i = 0; $i < variable_get('views_filterblock_num', 1); $i ++) { + $blocks[$i]['info'] = t('Views2 Filter Block #!i', array('!i' => $i)); + } + return $blocks; + + case 'view': + $block['content'] = _views_filterblock_block($delta); + return $block; + + case 'configure': + $options[''] = '-- Select One --'; + $result = db_query('SELECT * FROM {views_view}'); + while ($view = db_fetch_object($result)) { + $options[$view->name] = $view->description ? $view->description : $view->name; + $used[$view->name] = TRUE; + } + $default_views = views_get_all_views(); + foreach ($default_views as $name => $view) { + if ($view->page && !$used[$view->name]) { + $options[$view->name] = $view->description; } } - } - } - if (!$open) { - $newform["fieldset0"]['#collapsed'] = FALSE; - } + asort($options); - return $output . theme('views_filterblock_output', $newform); + $var = 'filterblock_view'; + $form[$var] = array( + '#type' => 'select', + '#title' => t('View'), + '#options' => $options, + '#default_value' => variable_get("$var.$delta", NULL), + '#description' => t('Select a view whose filter you want to display in the block'), + ); + return $form; + + case 'save': + $var = 'filterblock_view'; + variable_set("$var.$delta", $edit[$var]); + } } -function theme_views_filterblock_output($form) { - return drupal_render($form); +function _views_filterblock_block($delta) { + // Thanks to http://www.computerminds.co.uk/ + // displaying-exposed-filter-form-views-drupal-6-views-2 for most of this. + $var = 'filterblock_view'; + $view_name = variable_get("$var.$delta", NULL); + $view = views_get_view($view_name); + $display_id = 'default'; + $view->set_display($display_id); + $view->init_handlers(); + // Add the $delta to this so that it can test for it in _form_alter. + $form_state = array( + 'view' => $view, + 'delta' => $delta, + 'display' => $view->display_handler->display, + 'method' => 'get', + 'rerender' => TRUE, + 'no_redirect' => TRUE, + ); + $output = drupal_build_form('views_exposed_form', $form_state); + return $output; } /** * Implementation of hook_form_alter(). */ -function views_filterblock_form_alter($form_id, &$form) { - if ($form_id == 'views_filters') { - /** - * Hide the form displayed as part of the view, when the - * filterform is displayed in a block - */ - $name = $form['view']['#value']->name; - if (!$form['#views_filterblock']) { - // get the list of regions - global $theme_key; - $result = db_query("SELECT delta FROM {blocks} WHERE theme = '%s' AND module = 'views_filterblock'", $theme_key); - while ($block = db_fetch_object($result)) { - if (variable_get('views_filterblock_view.'. $block->delta, '') == $name) { - $form['#type'] = 'hidden'; - return; - } - } - } +function views_filterblock_form_views_exposed_form_alter(&$form, $form_state) { + /** + * Hide the form displayed as part of the view, when the + * filterform is displayed in a block. + */ + // Grab the delta straight from the form. + $delta = $form['#parameters'][1]['delta']; + if (is_null($delta)) { + // If it has no $delta, then it isn't in a block, and we hide it. + if (variable_get('views_filterblock_hide', 1) == 1) { + $form['#attributes'] = array('class' => 'views-filterblock-hidden'); + } + } + elseif (!is_null($delta)) { + // If it does have $delta we rename it so we don't get conflicting id's. + $form['#id'] = 'views-filterblock-'. $delta; } } + +function views_filterblock_init() { + drupal_add_css(drupal_get_path('module', 'views_filterblock') .'/views-filterblock.css'); +}