You are here

protected function ViewsUiBaseViewsWizard::default_display_filters_user in Views (for Drupal 7) 7.3

1 call to ViewsUiBaseViewsWizard::default_display_filters_user()
ViewsUiBaseViewsWizard::default_display_filters in plugins/views_wizard/views_ui_base_views_wizard.class.php

File

plugins/views_wizard/views_ui_base_views_wizard.class.php, line 672
Provides the interface and base class for Views Wizard plugins.

Class

ViewsUiBaseViewsWizard
A very generic Views Wizard class - can be constructed for any base table.

Code

protected function default_display_filters_user($form, $form_state) {
  $filters = array();
  if (!empty($form_state['values']['show']['type']) && $form_state['values']['show']['type'] != 'all') {
    $bundle_key = $this->entity_info['bundle keys']['bundle'];

    // Figure out the table where $bundle_key lives. It may not be the same as
    // the base table for the view; the taxonomy vocabulary machine_name, for
    // example, is stored in taxonomy_vocabulary, not taxonomy_term_data.
    $fields = views_fetch_fields($this->base_table, 'filter');
    if (isset($fields[$this->base_table . '.' . $bundle_key])) {
      $table = $this->base_table;
    }
    else {
      foreach ($fields as $field_name => $value) {
        if ($pos = strpos($field_name, '.' . $bundle_key)) {
          $table = substr($field_name, 0, $pos);
          break;
        }
      }
    }
    $table_data = views_fetch_data($table);

    // Check whether the bundle key filter handler is or an child of it
    // views_handler_filter_in_operator. If it's not just use a single value
    // instead of an array.
    $handler = $table_data[$bundle_key]['filter']['handler'];
    if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) {
      $value = drupal_map_assoc(array(
        $form_state['values']['show']['type'],
      ));
    }
    else {
      $value = $form_state['values']['show']['type'];
    }
    $filters[$bundle_key] = array(
      'id' => $bundle_key,
      'table' => $table,
      'field' => $bundle_key,
      'value' => $value,
    );
  }

  // @todo Figure out why this isn't part of node_views_wizard.
  if (!empty($form_state['values']['show']['tagged_with']['tids'])) {
    $filters['tid'] = array(
      'id' => 'tid',
      'table' => 'taxonomy_index',
      'field' => 'tid',
      'value' => $form_state['values']['show']['tagged_with']['tids'],
      'vocabulary' => $form_state['values']['show']['tagged_with']['vocabulary'],
    );

    // If the user entered more than one valid term in the autocomplete
    // field, they probably intended both of them to be applied.
    if (count($form_state['values']['show']['tagged_with']['tids']) > 1) {
      $filters['tid']['operator'] = 'and';

      // Sort the terms so the filter will be displayed as it normally would
      // on the edit screen.
      sort($filters['tid']['value']);
    }
  }
  return $filters;
}