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;
 }
  /**
   * Most subclasses will need to override this method to provide some fields
   * or a different row plugin.
   */
  protected function default_display_options($form, $form_state) {
    $display_options = array();
    $display_options['access']['type'] = 'none';
    $display_options['cache']['type'] = 'none';
    $display_options['query']['type'] = 'views_query';
    $display_options['exposed_form']['type'] = 'basic';
    $display_options['pager']['type'] = 'full';
    $display_options['style_plugin'] = 'default';
    $display_options['row_plugin'] = 'fields';

    // Add a least one field so the view validates and the user has already a preview.
    // Therefore the basefield could provide 'defaults][field]' in it's base settings.
    // If there is nothing like this choose the first field with a field handler.
    $data = views_fetch_data($this->base_table);
    if (isset($data['table']['base']['defaults']['field'])) {
      $field = $data['table']['base']['defaults']['field'];
    }
    else {
      foreach ($data as $field => $field_data) {
        if (isset($field_data['field']['handler'])) {
          break;
        }
      }
    }
    $display_options['fields'][$field] = array(
      'table' => $this->base_table,
      'field' => $field,
      'id' => $field,
    );

    return $display_options;
  }
コード例 #3
0
 /**
  * Set the base_table and base_table_alias.
  *
  * @return string
  *   The base table which is used in the current view "context".
  */
 function get_base_table()
 {
     if (!isset($this->base_table)) {
         // This base_table is coming from the entity not the field.
         $this->base_table = $this->view->base_table;
         // If the current field is under a relationship you can't be sure that the
         // base table of the view is the base table of the current field.
         // For example a field from a node author on a node view does have users as base table.
         if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
             $relationships = $this->view->display_handler->get_option('relationships');
             if (!empty($relationships[$this->options['relationship']])) {
                 $options = $relationships[$this->options['relationship']];
                 $data = views_fetch_data($options['table']);
                 $this->base_table = $data[$options['field']]['relationship']['base'];
             }
         }
     }
     return $this->base_table;
 }