diff --git a/sites/all/modules/contrib/reference_option_limit/reference_option_limit.views.inc b/sites/all/modules/contrib/reference_option_limit/reference_option_limit.views.inc index fdb1317..23b55bf 100644 --- a/sites/all/modules/contrib/reference_option_limit/reference_option_limit.views.inc +++ b/sites/all/modules/contrib/reference_option_limit/reference_option_limit.views.inc @@ -150,7 +150,7 @@ function reference_option_limit_views_handler_filter_get_matched_field_options($ * @return * An array of FormAPI options. */ -function reference_option_limit_views_handler_filter_get_value_options($filter_handler, $referred_entity_type, $referred_bundles) { +function reference_option_limit_views_handler_filter_get_value_options($filter_handler, $referred_entity_type, $referred_bundles, $form, $form_state) { $referred_entity_instances = field_info_instances($referred_entity_type); $limit_fields = array_filter($filter_handler->options['options_limit_fields']); @@ -179,15 +179,25 @@ function reference_option_limit_views_handler_filter_get_value_options($filter_h if ($handler_type == 'filter') { if ($handler->options['exposed']) { // Exposed filter. - // accept_exposed_input() has not yet been run on the handler at this - // stage, so we need to get it from the view. Furthermore, we can't - // call accept_exposed_input() ourselves as various other things it - // expects haven't happened yet. - $exposed_input = $handler->view->get_exposed_input(); - // This ends up as a nested array if the filter takes multiple values - // but nothing further one seems to be bothered by it! - if (isset($exposed_input[$handler->options['expose']['identifier']])) { - $match_values[$field_name_matching] = array($exposed_input[$handler->options['expose']['identifier']]); + $identifier = $handler->options['expose']['identifier']; + if (isset($form_state['values'][$identifier]) && $form_state['values'][$identifier] != 'All') { + $match_values[$field_name_matching] = array($form_state['values'][$identifier]); + } + else { + // accept_exposed_input() has not yet been run on the handler at this + // stage, so we need to get it from the view. Furthermore, we can't + // call accept_exposed_input() ourselves as various other things it + // expects haven't happened yet. + $exposed_input = $handler->view->get_exposed_input(); + + // This ends up as a nested array if the filter takes multiple values + // but nothing further one seems to be bothered by it! + if (isset($exposed_input[$identifier])) { + $match_values[$field_name_matching] = array($exposed_input[$identifier]); + } + elseif (isset($form[$identifier]['#default_value'])) { + $match_values[$field_name_matching] = array($form[$identifier]['#default_value']); + } } } else { diff --git a/sites/all/modules/contrib/reference_option_limit/reference_option_limit_handler_filter_limited_options_term_reference.inc b/sites/all/modules/contrib/reference_option_limit/reference_option_limit_handler_filter_limited_options_term_reference.inc index 09dabc6..ccb1ad4 100644 --- a/sites/all/modules/contrib/reference_option_limit/reference_option_limit_handler_filter_limited_options_term_reference.inc +++ b/sites/all/modules/contrib/reference_option_limit/reference_option_limit_handler_filter_limited_options_term_reference.inc @@ -16,6 +16,9 @@ * matching handlers and used to build the Entity Field Query to get the * options for the exposed form. */ + +module_load_include('inc', 'reference_option_limit', 'reference_option_limit.views'); + class reference_option_limit_handler_filter_limited_options_term_reference extends views_handler_filter_term_node_tid { function option_definition() { $options = parent::option_definition(); @@ -65,8 +68,26 @@ class reference_option_limit_handler_filter_limited_options_term_reference exten $referred_entity_type = 'taxonomy_term'; $referred_bundles = array($this->options['vocabulary']); + $identifier = $this->options['expose']['identifier']; + + // Add ajax to each exposed filter limiting this. + $limit_fields = array_filter($this->options['options_limit_fields']); + foreach ($limit_fields as $key) { + list($handler_type, $handler_id) = explode(':', $key); + if ($handler_type == 'filter') { + $handler = $this->view->display_handler->get_handler($handler_type, $handler_id); + if ($handler->options['exposed']) { + $form[$handler->options['expose']['identifier']]['#ajax'] = array( + 'limited_field' => $identifier, + 'wrapper' => $identifier, + 'callback' => 'reference_option_limit_views_exposed_filter_ajax_callback', + ); + } + } + } + // Get the options for the value form. - $options = reference_option_limit_views_handler_filter_get_value_options($this, $referred_entity_type, $referred_bundles); + $options = reference_option_limit_views_handler_filter_get_value_options($this, $referred_entity_type, $referred_bundles, $form, $form_state); // Gacked from parent class. $default_value = (array) $this->value; @@ -103,6 +124,16 @@ class reference_option_limit_handler_filter_limited_options_term_reference exten '#options' => $options, '#size' => min(9, count($options)), '#default_value' => $default_value, + '#prefix' => '
', + '#suffix' => '
', ); } } + +/** + * Ajax callback. + */ +function reference_option_limit_views_exposed_filter_ajax_callback($form, $form_state) { + $key = $form_state['triggering_element']['#ajax']['limited_field']; + return $form[$key]; +}