There's a hook for that! hook_views_pre_render does exactly what I needed. Here's the code
/** * Check for Board Member status and overwrite field_role if TRUE . */ function mymodule_views_pre_render(&$view) { $results = &$view->result; foreach ($results as $key => $result) { if (($view->name == 'staff') && ($view->current_display == 'panel_pane_1')) { $field_board = $result->_field_data['nid']['entity']->field_staff_leader; if ($field_board['und'][0]['value'] == '2') { $results[$key]->field_field_role[0]['rendered']['#markup'] = 'Board Member'; } } }To break it down: First you need to access the view's results, and then of course make sure that you're applying your code to the correct view display. If you are not sure what the view name or display id is, add dsm($view); to your code (be sure you have the devel module enabled), and your needed values will be in $view->name, and $view->current_display, respectively.
/** * Check for Board Member status and overwrite field_role if TRUE . */ function mymodule_views_pre_render(&$view) { $results = &$view->result; foreach ($results as $key => $result) { if (($view->name == 'staff') && ($view->current_display == 'panel_pane_1')) {Once you have targeted the correct view/display, check the field value:
$field_board = $result->_field_data['nid']['entity']->field_staff_leader; if ($field_board['und'][0]['value'] == '2') {...and then add your custom markup:
$results[$key]->field_field_role[0]['rendered']['#markup'] = 'Board Member';Then you may go enjoy your fully functional Death Star. Er, View.
No comments:
Post a Comment