Browse Source

Filter box : change the meaning of 'Autres' checkbox into 'all other potential values'

Yves Chedemois 14 years ago
parent
commit
56ad773ec6
1 changed files with 15 additions and 3 deletions
  1. 15 3
      fgcf.module

+ 15 - 3
fgcf.module

@@ -434,7 +434,7 @@ function fgcf_filter_form($form_state) {
     '#options' => array(
       '1'    => t('Inter-entreprises'),
       '2'    => t('Intra-entreprise'),
-      '3'   => t('Autres'),
+      '999'  => t('Autres'),
     ),
     '#default_value' => $modalite,
   );
@@ -453,7 +453,7 @@ function fgcf_filter_form($form_state) {
 function fgcf_filter_form_submit($form, &$form_state) {
   foreach (array('modalite', 'dif') as $key) {
     $value = $form_state['values'][$key];
-    //$form_state['storage'][$key] = $value;
+    $form_state['storage'][$key] = $value;
     $_SESSION['fgcf'][$key] = $value;
   }
 }
@@ -475,10 +475,22 @@ function _fgcf_filter_form_translate_values() {
   if (isset($_SESSION['fgcf']['modalite'])) {
     $modalites = array_filter($_SESSION['fgcf']['modalite']);
     if (!empty($modalites)) {
+      // 'Autres' (999) means 'all other values than 1 and 2'.
+      // Translate this into actual values.
+      if (isset($modalites[999])) {
+        // Get the actual possible values from the field definition.
+        $field = content_fields('field_fgcf_fiche_modalite', 'fgcf_fiche');
+        $allowed_values = content_allowed_values($field);
+        // Remove the first 2 options.
+        unset($allowed_values[1], $allowed_values[2]);
+        // Remove the 'proxy' 'Autres' choice.
+        unset($modalites[999]);
+        // Add the actual values.
+        $modalites += drupal_map_assoc(array_keys($allowed_values));
+      }
       $values['modalites'] = implode('+', array_keys($modalites));
     }
   }
-
   return $values;
 }