Created
May 31, 2013 09:43
-
-
Save bdecarne/5683948 to your computer and use it in GitHub Desktop.
Drupal : Show exposed filters form in a custom block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* implements hook_block_info() | |
**/ | |
function test_block_info(){ | |
$blocks = array(); | |
$blocks['custom_exposed_filter_form'] = array( | |
'info' => t('Exposed filter form'), | |
'cache' => DRUPAL_NO_CACHE, | |
); | |
return $blocks; | |
} | |
/** | |
* implements hook_block_view() | |
**/ | |
function test_block_view($delta = ''){ | |
$block = array(); | |
switch($delta){ | |
case 'custom_exposed_filter_form': | |
$block['subject'] = t('Exposed filter form'); | |
$block['content'] = _test_get_exposed_filter_form(); | |
break; | |
} | |
return $block; | |
} | |
/** | |
* Function to get the Exposed filter form | |
**/ | |
function _test_get_exposed_filter_form(){ | |
// Get a view from the database or from default views . "test" is the view name. | |
$view = views_get_view('test'); | |
// Set the display as current. | |
$view->set_display('page'); | |
// Acquire and attach all of the handlers to the view. | |
$view->init_handlers(); | |
$exposed_form = $view->display_handler->get_plugin('exposed_form'); | |
return $exposed_form->render_exposed_form(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment