diff --git a/handlers/views_handler_argument.inc b/handlers/views_handler_argument.inc index eca666a..0148b55 100644 --- a/handlers/views_handler_argument.inc +++ b/handlers/views_handler_argument.inc @@ -133,6 +133,21 @@ class views_handler_argument extends views_handler { } /** + * Determine if this argument passes its value through to a filter criterion, + * therefore not doing the query itself. + */ + function is_pass_through() { + return !empty($this->options['pass_through_enable']) && !empty($this->options['pass_through']); + } + + /** + * Get the id of the filter criterion handler which will receive the value. + */ + function get_pass_through() { + return $this->options['pass_through']; + } + + /** * Determine if the argument needs a style plugin. * * @return TRUE/FALSE @@ -176,6 +191,8 @@ class views_handler_argument extends views_handler { ), ); $options['validate_options'] = array('default' => array(), 'export' => FALSE); + $options['pass_through_enable'] = array('default' => 0); + $options['pass_through'] = array('default' => '', 'translatable' => TRUE); return $options; } @@ -373,6 +390,43 @@ class views_handler_argument extends views_handler { ), '#fieldset' => 'argument_present', ); + + // The cached view object we have available doesn't have information + // about filters. Hardcoding the list until we figure out how to fix that. + $status = new stdClass; + $status->definition = array('group' => 'Content', 'title' => 'Published'); + $timestamp = new stdClass; + $timestamp->definition = array('group' => 'Content', 'title' => 'Created date'); + $this->view->display_handler->handlers['filter'] = array( + 'status' => $status, + 'timestamp' => $timestamp, + ); + + $filters = array('0' => 'Please select'); + // @todo Replace the logic in the foreach with $handler->ui_name() once the + // situation above gets resolved. + foreach ($this->view->display_handler->handlers['filter'] as $key => $info) { + $filters[$key] = check_plain($info->definition['group'] . ': ' . $info->definition['title']); + } + + $form['pass_through_enable'] = array( + '#type' => 'checkbox', + '#title' => t('Pass the value to a filter criterion'), + '#default_value' => $this->options['pass_through_enable'], + '#fieldset' => 'argument_present', + ); + $form['pass_through'] = array( + '#type' => 'select', + '#title' => t('Select filter criterion'), + '#title_display' => 'invisible', + '#default_value' => $this->options['pass_through'], + '#options' => $filters, + '#process' => array('ctools_dependent_process'), + '#dependency' => array( + 'edit-options-pass-through-enable' => array('1'), + ), + '#fieldset' => 'argument_present', + ); } function options_validate(&$form, &$form_state) { diff --git a/includes/view.inc b/includes/view.inc index ff22186..05bbf2b 100644 --- a/includes/view.inc +++ b/includes/view.inc @@ -463,6 +463,7 @@ class view extends views_db_object { $title = $this->display_handler->get_option('title'); $this->build_info['breadcrumb'] = array(); + $this->build_info['pass_through'] = array(); $breadcrumb_args = array(); $substitutions = array(); @@ -502,7 +503,10 @@ class view extends views_db_object { } else { $arg_title = $argument->get_title(); - $argument->query($this->display_handler->use_group_by()); + // Only do the query if the argument is not passed to a filter. + if (!$argument->is_pass_through()) { + $argument->query($this->display_handler->use_group_by()); + } } // Add this argument's substitution @@ -531,6 +535,12 @@ class view extends views_db_object { $title = $argument->options['title']; } + // See if the argument value needs to be passed to a filter. + if ($argument->is_pass_through()) { + $filter_handler_id = $argument->get_pass_through(); + $this->build_info['pass_through'][$filter_handler_id] = $arg; + } + $breadcrumb_args[] = $arg; } else { @@ -658,12 +668,13 @@ class view extends views_db_object { } // Build all the filters. + $argument_status = $this->_build_arguments(); $this->_build('filter'); $this->build_sort = TRUE; // Arguments can, in fact, cause this whole thing to abort. - if (!$this->_build_arguments()) { + if (!$argument_status) { $this->build_time = microtime(TRUE) - $start; $this->attach_displays(); return $this->built; @@ -737,6 +748,10 @@ class view extends views_db_object { $handlers = &$this->$key; foreach ($handlers as $id => $data) { if (!empty($handlers[$id]) && is_object($handlers[$id])) { + // Pass the specified argument values to its destination filters. + if ($key == 'filter' && array_key_exists($id, $this->build_info['pass_through'])) { + $handlers[$id]->value = $this->build_info['pass_through'][$id]; + } // Give this handler access to the exposed filter input. if (!empty($this->exposed_data)) { $rc = $handlers[$id]->accept_exposed_input($this->exposed_data);