diff --git a/hierarchical_select.info b/hierarchical_select.info index 14990d7..2f24be6 100644 --- a/hierarchical_select.info +++ b/hierarchical_select.info @@ -4,4 +4,4 @@ package = Form Elements core = 7.x -files[] = tests/internals.test +files[] = tests/internals.test \ No newline at end of file diff --git a/includes/common.inc b/includes/common.inc index 1451721..abb9929 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -374,6 +374,14 @@ function hierarchical_select_common_config_form_submit($form, &$form_state) { } /** + * Helper function that adds the JS to make Hierarchical Select work when used + * as a Views exposed filter. + */ +function hierarchical_select_common_add_views_js() { + drupal_add_js(drupal_get_path('module', 'hierarchical_select') .'/includes/views.js'); +} + +/** * Get the form element of a form that has a certain lineage of parents. * * @param $form diff --git a/includes/views.js b/includes/views.js index d5b5e3e..001370f 100644 --- a/includes/views.js +++ b/includes/views.js @@ -13,7 +13,7 @@ if (Drupal.jsEnabled) { - $(document).ready(function(){ + (function ($) { $('.view-filters form').submit(function() { // Remove the Hierarchical Select form build id and the form id, to // prevent them from ending up in the GET URL. @@ -25,5 +25,5 @@ if (Drupal.jsEnabled) { .find('.hierarchical-select-wrapper') .trigger('prepare-GET-submit'); }); - }); + }(jQuery)); } diff --git a/modules/hs_taxonomy_views.info b/modules/hs_taxonomy_views.info index a17c657..22846b7 100644 --- a/modules/hs_taxonomy_views.info +++ b/modules/hs_taxonomy_views.info @@ -4,6 +4,6 @@ dependencies[] = hierarchical_select dependencies[] = hs_taxonomy dependencies[] = views package = Form Elements -core = 6.x +core = 7.x files[] = hs_taxonomy_views_handler_filter_term_node_tid.inc diff --git a/modules/hs_taxonomy_views.module b/modules/hs_taxonomy_views.module index 6e06490..21aacb1 100644 --- a/modules/hs_taxonomy_views.module +++ b/modules/hs_taxonomy_views.module @@ -45,20 +45,16 @@ function hs_taxonomy_views_menu() { * Implementation of hook_form_alter(). */ function hs_taxonomy_views_form_alter(&$form, $form_state, $form_id) { - // if ($form_id == 'views_ui_edit_view_form') { - // Add JS and CSS required for Hierarchical Select to work. - _hierarchical_select_setup_js(); - // Ensure that Drupal.HierarchicalSelect.prepareGETSubmit() gets called. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc'; + + // Add JS and CSS required for Hierarchical Select to work. hierarchical_select_common_add_views_js(); } if ($form_id == 'views_ui_config_item_form' - && $form_state['type'] == 'filter' - && $form_state['handler']->table == 'taxonomy_term_node' - && $form_state['handler']->field == 'tid') { + && $form_state['type'] == 'filter') { require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc'; $view_name = $form_state['view']->name; @@ -84,6 +80,24 @@ function hs_taxonomy_views_form_alter(&$form, $form_state, $form_id) { } } +/* function hs_taxonomy_views_form_views_exposed_form_alter(&$form, &$form_state) { + $js_code="jQuery(function(){ + for(ajax_object in Drupal.ajax) + if(Drupal.ajax[ajax_object].options) + jQuery.extend(Drupal.ajax[ajax_object].options.data,Drupal.settings.exposed_form_info); + });"; + + $form_info_array = array( + 'form_id' => $form['#form_id'], + 'form_build_id' => $form['#build_id'], + 'form_token' => $form['#token'], + ); + + drupal_add_js(array('exposed_form_info' => $form_info_array), 'setting'); + drupal_add_js($js_code,array('type' => 'inline', 'weight' => 100)); +}*/ + + //---------------------------------------------------------------------------- // Menu system callbacks. @@ -150,7 +164,7 @@ function hs_taxonomy_views_json($view_name, $display_id) { views_set_current_view($view); } - return hierarchical_select_json(); + return hierarchical_select_ajax(); } @@ -162,101 +176,25 @@ function hs_taxonomy_views_json($view_name, $display_id) { */ function hs_taxonomy_views_api() { return array( - 'api' => 2, + 'api' => 3, 'path' => drupal_get_path('module', 'hierarchical_select') . '/modules', ); } /** - * Implementation of hook_views_handlers(). - */ -function hs_taxonomy_views_handlers() { - return array( - 'handlers' => array( - // Provide a subclass of the term filter handler, to make it possible to - // use Hierarchical Select in Views. - 'hs_taxonomy_views_handler_filter_term_node_tid' => array( - 'parent' => 'views_handler_filter_term_node_tid', - ), - 'hs_taxonomy_views_handler_filter_term_node_tid_depth' => array( - 'parent' => 'hs_taxonomy_views_handler_filter_term_node_tid', - ), - ) - ); -} - -/** - * Implementation of hook_views_data_alter(). + * Implementation of hook_field_views_data_alter(). */ -function hs_taxonomy_views_views_data_alter(&$data) { - // Term view type, tid field. - $data['taxonomy_term_data']['tid'] = array( - 'title' => t('Term ID'), - 'help' => t('The taxonomy term ID.'), - 'field' => array( - 'handler' => 'views_handler_field_numeric', - 'skip base' => array('node', 'node_revision'), - ), - 'sort' => array( - 'handler' => 'views_handler_sort', - ), - 'argument' => array( - 'handler' => 'views_handler_argument_numeric', - 'skip base' => array('node', 'node_revision'), - ), - // Override the views_handler_filter_term_node_tid filter handler: use our - // hs_taxonomy_views_handler_filter_term_node_tid subclass instead. - 'filter' => array( - 'handler' => 'hs_taxonomy_views_handler_filter_term_node_tid', - 'hierarchy table' => 'taxonomy_term_hierarchy', - 'numeric' => TRUE, - 'skip base' => array('node', 'node_revision'), - ), - ); - - // Node view type, tid field. - $data['taxonomy_term_node']['tid'] = array( - 'title' => t('Term ID'), - 'help' => t('The taxonomy term ID.'), - 'field' => array( - 'title' => t('All terms'), - 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'), - 'handler' => 'views_handler_field_term_node_tid', - 'skip base' => 'taxonomy_term_data', - ), - 'argument' => array( - 'handler' => 'views_handler_argument_term_node_tid', - 'name table' => 'taxonomy_term_data', - 'name field' => 'name', - 'empty name field' => t('Uncategorized'), - 'numeric' => TRUE, - 'skip base' => 'taxonomy_term_data', - ), - // Override the views_handler_filter_term_node_tid filter handler: use our - // hs_taxonomy_views_handler_filter_term_node_tid subclass instead. - 'filter' => array( - 'title' => t('Term'), - 'handler' => 'hs_taxonomy_views_handler_filter_term_node_tid', - 'hierarchy table' => 'taxonomy_term_hierarchy', - 'numeric' => TRUE, - 'skip base' => 'taxonomy_term_data', - ), - ); - - // Node view type, tid with depth field. - $data['node']['term_node_tid_depth'] = array( - 'group' => t('Taxonomy'), - 'title' => t('Term ID (with depth)'), - 'help' => t('The depth filter is more complex, so provides fewer options.'), - 'real field' => 'vid', - 'argument' => array( - 'handler' => 'views_handler_argument_term_node_tid_depth', - 'accept depth modifier' => TRUE, - ), - 'filter' => array( - 'handler' => 'hs_taxonomy_views_handler_filter_term_node_tid_depth', - ), - ); +function hs_taxonomy_views_field_views_data_alter(&$result, $field, $module) { + if ($module == 'taxonomy') { + foreach ($result as $table => $data) { + $field_name = $field['field_name']; + foreach ($data as $column => $value) { + if (array_key_exists('filter', $value)) { + $result[$table][$column]['filter']['handler'] = 'hs_taxonomy_views_handler_filter_term_node_tid'; + } + } + } + } } @@ -285,7 +223,7 @@ function hs_taxonomy_views_config_form($form, $form_state, $view, $display_id, $ // Add the Hierarchical Select config form. $module = 'hs_taxonomy_views'; $params = array( - 'optional' => (bool) $filter['expose']['optional'], + 'optional' => (bool) $filter['expose']['required'], 'filter_id' => $filter_id, 'vid' => $filter['vid'], 'exclude_tid' => NULL, @@ -317,7 +255,7 @@ function hs_taxonomy_views_config_form($form, $form_state, $view, $display_id, $ 'entities' => t('nodes'), ); $max_hierarchy_depth = _hs_taxonomy_hierarchical_select_get_depth($vocabulary->vid); - $preview_is_required = !(bool) $filter['expose']['optional']; + $preview_is_required = !(bool) $filter['expose']['required']; $form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required); $form['link'] = array( @@ -370,7 +308,7 @@ function hs_taxonomy_views_common_config_form_submit($form, &$form_state) { $view->display[$display_id]->display_options['filters'][$filter_id]['expose']['use_operator'] = 0; $view->save(); - views_object_cache_clear('view', $view_name); + ctools_object_cache_clear('view', $view_name); drupal_set_message(t("Because you've enabled the 'Save Lineage' setting, the operator has been set to 'AND' and cannot be changed by the end user.")); } } @@ -579,11 +517,8 @@ function hs_taxonomy_views_hierarchical_select_config_info() { foreach (array_keys($view->display) as $display_id) { if (isset($view->display[$display_id]->display_options['filters']) && count($view->display[$display_id]->display_options['filters'])) { foreach ($view->display[$display_id]->display_options['filters'] as $filter) { - if (isset($filter['type']) && $filter['type'] == 'hierarchical_select' - && ((isset($filter['table']) && $filter['table'] == 'taxonomy_term_node' - && isset($filter['field']) && $filter['field'] == 'tid') - || (isset($filter['table']) && $filter['table'] == 'node' - && isset($filter['field']) && $filter['field'] == 'term_node_tid_depth'))) { + // @todo: find a way to single out taxonomy fields + if (isset($filter['type']) && $filter['type'] == 'hierarchical_select') { $vocabulary = taxonomy_vocabulary_load($filter['vid']); $filter_label = (!empty($filter['expose']['label'])) ? $filter['expose']['label'] : t('Taxonomy: Term'); diff --git a/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc b/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc index 1f1a4c6..8fa77f7 100644 --- a/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc +++ b/modules/hs_taxonomy_views_handler_filter_term_node_tid.inc @@ -22,11 +22,9 @@ class hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte // If you can live with a reload of the View edit form, you can wrap the // code below in such a check. - // Add JS and CSS required for Hierarchical Select to work. - _hierarchical_select_setup_js(); - // Ensure that Drupal.HierarchicalSelect.prepareGETSubmit() gets called. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc'; + // Add JS and CSS required for Hierarchical Select to work. hierarchical_select_common_add_views_js(); } @@ -49,7 +47,9 @@ class hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte $view_name = $this->view->name; $filter_id = $this->options['id']; $display_id = _hs_taxonomy_views_get_display_id_for_filter($this->view, $filter_id); - $optional = $this->options['expose']['optional']; + // @TODO: optional fixen!! + //$optional = $this->options['expose']['optional']; + $optional = FALSE; $config_id = "taxonomy-views-$view_name-$display_id-$filter_id"; @@ -168,7 +168,7 @@ class hs_taxonomy_views_handler_filter_term_node_tid extends views_handler_filte '#markup' => l(t('Configure Hierarchical Select'), _hs_taxonomy_views_config_path($this->view->name, $display_id, $filter_id)), '#suffix' => '', // Doesn't work because #process is not called for #type = markup form items. - '#process' => array('views_process_dependency'), + '#process' => array('ctools_dependent_process'), '#dependency' => array('radio:options[type]' => array('hierarchical_select')), // Set #input = TRUE so that #process will be called. '#input' => TRUE,