You are here

function global_filter_add_view_results in Views Global Filter 6

Same name and namespace in other branches
  1. 8 global_filter.widgets.inc \global_filter_add_view_results()
  2. 7 global_filter.widgets.inc \global_filter_add_view_results()
1 call to global_filter_add_view_results()
global_filter_form in ./global_filter.module
Creates the drop-down selector for the global selector field.

File

./global_filter.module, line 366
global_filter.module

Code

function global_filter_add_view_results(&$options, $view_id) {
  $view = views_get_view($view_id);
  if (!is_object($view)) {
    drupal_set_message(t('Global Filter: could not find view: %view', array(
      '%view' => empty($view_id) ? t('no name specified') : $view_id,
    )), 'error');
    return;
  }
  $view
    ->init_display();
  $view
    ->pre_execute();
  $view
    ->execute();

  // Pick the first non-id field of each returned row as the next value for
  // the filter.
  foreach ($view->result as $row) {
    $row_as_array = (array) $row;
    foreach ($row_as_array as $fid => $value) {

      // Ignore the view's base fields like  'nid', 'uid', 'cid', 'tid', 'aid' {accesslog}
      if ($fid != $view->base_field) {
        break;
      }
    }
    $key = $row_as_array[$view->base_field];
    $options[empty($key) ? $value : $key] = $value;
  }
}