Created
December 14, 2011 04:54
-
-
Save kevinchampion/1475316 to your computer and use it in GitHub Desktop.
Using hook_views to programmatically filter a view in Views 3, Drupal 7
This file contains hidden or 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
function lsadataclassify_views_pre_view(&$view, &$display_id, &$args){ | |
if ($view->name === 'protection_measures' && $view->current_display === 'page'){ | |
} | |
} |
This file contains hidden or 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
function lsadataclassify_views_pre_view(&$view, &$display_id, &$args){ | |
if ($view->name === 'protection_measures' && $view->current_display === 'page' && isset($args[0])){ | |
$node = node_load($args[0]); | |
$sensitivity = $node->field_research_sensitivity[$node->language][0]['value']; | |
$tids = array(); | |
switch ($sensitivity) { | |
case 'high': | |
$tids = array(5, 6, 7); | |
break; | |
case 'moderate': | |
$tids = array(6, 7); | |
break; | |
case 'low': | |
$tids = array(7); | |
break; | |
} | |
$view->display['page']->handler->options['filters']['field_pm_sensitivity_termref_tid']['value'] = $tids; | |
} | |
} |
This file contains hidden or 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
$view->display['page']->handler->options['filters']; |
This file contains hidden or 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
$view = views_get_page_view(); | |
$pm_nodes = array(); | |
// loop through each row of the view which contains a node | |
foreach ($view->result as $key => $entity){ | |
// node of protection measure | |
$pm_nodes[$key] = $entity->_field_data['nid']['entity']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment