? 699252-8-field_filter.patch
Index: handlers/views_handler_field.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_field.inc,v
retrieving revision 1.14.2.39
diff -u -r1.14.2.39 views_handler_field.inc
--- handlers/views_handler_field.inc	13 Aug 2010 19:41:20 -0000	1.14.2.39
+++ handlers/views_handler_field.inc	5 Oct 2010 22:37:08 -0000
@@ -56,6 +56,16 @@
     );
   }
 
+  function is_filter_value() { return TRUE; }
+
+  /**
+   * Returns the field alias or the formula of the field.
+   */
+  function get_field_alias() {
+    $this->ensure_my_table();
+    return "$this->table_alias.$this->real_field";
+  }
+
   /**
    * Called to add the field to a query.
    */
Index: handlers/views_handler_filter.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_filter.inc,v
retrieving revision 1.6.2.16
diff -u -r1.6.2.16 views_handler_filter.inc
--- handlers/views_handler_filter.inc	13 Aug 2010 20:51:33 -0000	1.6.2.16
+++ handlers/views_handler_filter.inc	5 Oct 2010 22:37:08 -0000
@@ -48,6 +48,7 @@
     $options['value'] = array('default' => '');
     $options['group'] = array('default' => '0');
     $options['exposed'] = array('default' => FALSE);
+    $options['field_filter'] = array('default' => '');
     $options['expose'] = array(
       'contains' => array(
         'operator' => array('default' => FALSE),
@@ -89,6 +90,7 @@
     $form['op_val_start'] = array('#value' => '<div class="clear-block">');
     $this->show_operator_form($form, $form_state);
     $this->show_value_form($form, $form_state);
+    $this->show_field_filter_form($form, $form_state);
     $form['op_val_end'] = array('#value' => '</div>');
     if ($this->can_expose()) {
       $this->show_expose_form($form, $form_state);
@@ -194,6 +196,32 @@
   function value_submit($form, &$form_state) { }
 
   /**
+   * Shortcut to display the field_filter form.
+   */
+  function show_field_filter_form(&$form, &$form_state) {
+    $this->field_filter_form($form, $form_state);
+  }
+  
+  /**
+   * Provide a form for field_filter options.
+   */
+  function field_filter_form(&$form, &$form_state) {
+    // Get all possible fields.
+    $options[''] = t('None');
+    foreach ($this->view->display_handler->get_handlers('field') as $id => $handler) {
+      if ($handler->is_filter_value()) {
+        $options[$id] = $handler->label();
+      }
+    }
+    $form['field_filter'] = array(
+      '#title' => t('Field filter'),
+      '#type' => 'select',
+      '#default_value' => $this->options['field_filter'],
+      '#options' => $options,
+    );
+  }
+
+  /**
    * Handle the 'left' side fo the exposed options form.
    */
   function expose_form_left(&$form, &$form_state) {
@@ -499,10 +527,32 @@
    * and $this->value respectively.
    */
   function query() {
+    dsm($this);
+    if ($this->options['field_filter']) {
+      return $this->query_field();
+    }
     $this->ensure_my_table();
     $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . $this->operator . " '%s'", $this->value);
   }
 
+  function query_field() {
+    if ($field_alias = $this->field_filter_alias()) {
+      $this->ensure_my_table();
+      $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . $this->operator ." $field_alias");
+    }
+  }
+
+  function field_filter_alias() {
+    if ($field = $this->options['field_filter']) {
+      // get the instance of the field filter, to check whether to return its
+      // field filter instance, if its empty the field does not support it.
+      $handler = $this->view->display_handler->get_handler('field', $field);
+      if ($handler->is_filter_value() && $alias = $handler->get_field_alias()) {
+        return $alias;
+      }
+    }
+  }
+
   /**
    * Can this filter be used in OR groups?
    *
Index: handlers/views_handler_filter_numeric.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_filter_numeric.inc,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 views_handler_filter_numeric.inc
--- handlers/views_handler_filter_numeric.inc	8 Mar 2010 19:53:47 -0000	1.7.2.1
+++ handlers/views_handler_filter_numeric.inc	5 Oct 2010 22:37:08 -0000
@@ -208,6 +208,10 @@
   }
 
   function query() {
+    if ($this->options['field_filter']) {
+      return $this->query_field();
+    }
+
     $this->ensure_my_table();
     $field = "$this->table_alias.$this->real_field";
 
Index: handlers/views_handler_filter_string.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_filter_string.inc,v
retrieving revision 1.7.2.5
diff -u -r1.7.2.5 views_handler_filter_string.inc
--- handlers/views_handler_filter_string.inc	29 Apr 2010 19:29:15 -0000	1.7.2.5
+++ handlers/views_handler_filter_string.inc	5 Oct 2010 22:37:08 -0000
@@ -228,6 +228,10 @@
    * and $this->value respectively.
    */
   function query() {
+    if ($this->options['field_filter']) {
+      return $this->query_field();
+    }
+
     $this->ensure_my_table();
     $field = "$this->table_alias.$this->real_field";
     $upper = $this->case_transform();
Index: includes/view.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/view.inc,v
retrieving revision 1.151.2.37
diff -u -r1.151.2.37 view.inc
--- includes/view.inc	17 Aug 2010 21:12:06 -0000	1.151.2.37
+++ includes/view.inc	5 Oct 2010 22:37:08 -0000
@@ -632,9 +632,6 @@
       }
     }
 
-    // Build all the filters.
-    $this->_build('filter');
-
     $this->build_sort = TRUE;
 
     // Arguments can, in fact, cause this whole thing to abort.
@@ -656,6 +653,9 @@
       $this->_build('field');
     }
 
+    // Build all the filters.
+    $this->_build('filter');
+
     // Build our sort criteria if we were instructed to do so.
     if (!empty($this->build_sort)) {
       // Allow the style handler to deal with sorting.
