diff --git a/views_filters_selective.module b/views_filters_selective.module old mode 100644 new mode 100755 index caa4bae..ebe36cb --- a/views_filters_selective.module +++ b/views_filters_selective.module @@ -28,3 +28,66 @@ function views_filters_selective_views_ajax_data_alter(&$commands, $view) { $commands[] = ajax_command_invoke(NULL, "attachBehaviors"); } } + +/** + * Implements hook_form_views_exposed_form_alter(). + */ +function views_filters_selective_form_views_exposed_form_alter(&$form, &$form_state, $form_id){ + + /* + * Added just "select" html types + * because they are most used checkbox fields. + * But can be added all fields you need in "$type_to_remove" + */ + $type_to_remove = array('select'); + $type = '#type'; + $options = '#options'; + $access = '#access'; + $theme = '#theme'; + $info = '#info'; + $value_key = 'value'; + $val_to_remove = array(); + + foreach ($form as $key => &$formVar){ + if ( is_Array($formVar) && array_key_exists ($type, $formVar )) { + + $searchKey = array_search($formVar[$type], $type_to_remove, TRUE); + if ($searchKey !== FALSE){ + if (array_key_exists ($options, $formVar) && is_array($formVar[$options]) && empty($formVar[$options])){ + if (array_key_exists ($theme, $formVar)){ + array_push($val_to_remove, $key); + $formVar[$access] = FALSE; + } + } + } + } + } + unset($formVar); + + if (!empty($val_to_remove)){ + foreach ($form[$info] as $key => &$infoVal){ + if (is_Array($infoVal) && !empty($infoVal) && array_key_exists($value_key, $infoVal)) { + + $keySearch = array_search($infoVal[$value_key], $val_to_remove, TRUE); + + if ($keySearch !== FALSE){ + unset($val_to_remove[$keySearch]); + unset($form[$info][$key]); + } + } + } + unset($infoVal); + } + + /* + * To show variables with "devel" module installed + * You can place this code everywhere + * NOT NECESSARY IN PRODUCTION SITE + * + * if (module_exists('devel')){ + * dsm($form); + * } + * + * END UNNECESSARY CODE + */ +}