瀏覽代碼

- "hidden" and "value" elements no longer removed by default
- "#value" property no longer removed by default
- simplified integration with app modules: qbf_transform_form is no longer explicitly invoked by them, thanks to hook_forms in qbf
- temporary hard-coded hook_forms implementation, to be replaced by settings UI
- added support for display information on a QBF form, currently hardcoded, to be replaced by dynamic query generation

Frederic G. Marand 16 年之前
父節點
當前提交
5c02a99a4e
共有 1 個文件被更改,包括 45 次插入29 次删除
  1. 45 29
      qbf.module

+ 45 - 29
qbf.module

@@ -7,14 +7,18 @@
  *
  * @copyright 2008 Ouest Systemes Informatiques (OSInet)
  * @author Frederic G. MARAND
- * @version $Id: qbf.module,v 1.3 2008-08-25 17:40:53 marand Exp $
+ * @version $Id: qbf.module,v 1.4 2008-08-26 16:24:07 marand Exp $
  * @license CeCILL 2.0
  * @package QBF
  */
 
 define('QBF_LEVEL_REMOVE',           0);
-define('QBF_LEVEL_OPTIONAL',         1);
-define('QBF_LEVEL_REQUIRED',         2);
+define('QBF_LEVEL_DISPLAY',          1); // Display only, don't use
+define('QBF_LEVEL_OPTIONAL',         2);
+define('QBF_LEVEL_REQUIRED',         3);
+
+define('QBF_PATH_QUERY',             'qbf/query');
+
 
 function _qbf_view($usNodeType = NULL)
   {
@@ -60,7 +64,7 @@ function qbf_rewrite_form($form)
 function qbf_transform_form($form_id)
   {
   $arArgs = func_get_args();
-
+//dsm(array('qtf' => $arArgs));
   // Fetch the basic form and rename it, passing it the caller's arguments
   $form = call_user_func_array('drupal_retrieve_form', $arArgs);
   $newFormId = "qbf_$form_id";
@@ -68,6 +72,7 @@ function qbf_transform_form($form_id)
   // Only keep the children of the form and QBF properties on the form itself
   $elements = array();
   $newForm = array();
+  $newForm['#qbf_source_form_id'] = $form_id;
   if (in_array('#qbf', element_properties($form)))
     {
     $newForm += $form['#qbf'];
@@ -84,6 +89,9 @@ function qbf_transform_form($form_id)
     }
 
   $newForm['#id'] = $newFormId;
+  $newForm['#multistep'] = TRUE;
+  $newForm['#redirect']  = FALSE;
+  $newForm['#after_build'][] = 'qbf_after_build';
 // dsm($newForm);
   return $newForm;
   }
@@ -107,13 +115,13 @@ function _qbf_transform_element($key, array $element)
     (
     'button'         => NULL,
     'file'           => NULL,
-    'hidden'         => NULL,
+    // 'hidden'         => NULL,
     'markup'         => NULL,
     'password'       => NULL,
     'radio'          => NULL,
     'submit'         => NULL,
     'textarea'       => 'textfield',
-    'value'          => NULL,
+    // 'value'          => 'value',
     );
 
   // Properties without a default transformation are not transformed
@@ -135,7 +143,6 @@ function _qbf_transform_element($key, array $element)
     '#submit'        => NULL,
     '#tree'          => NULL,
     '#validate'      => NULL,
-    '#value'         => NULL,
     );
 
   // Property values causing element removal
@@ -218,36 +225,45 @@ function _qbf_transform_element($key, array $element)
   return $ret;
   }
 
-function qbf_search()
-  {
-  dsm('qs');
-  }
-
 function qbf_perm()
   {
   $ret = array('use qbf search functions');
   return $ret;
   }
 
-function qbf_menu($may_cache)
+/**
+ * Implement hook_forms
+ *
+ * @todo dynamically build the list of forms
+ *
+ * @return array
+ */
+function qbf_forms()
   {
-  $items = array();
+  $forms['qbf_job_form'] = array
+    (
+    'callback'           => 'qbf_transform_form',
+    'callback arguments' => array('job_form'),
+    );
+  return $forms;
+  }
 
-  if ($may_cache)
+function qbf_after_build($form, $form_values)
+  {
+  $arQuery = array();
+  dsm($form_values);
+  foreach (element_children($form) as $childName)
     {
-    $items[] = array
-      (
-      'path'      => 'qbf/query',
-      'access'    => user_access('use qbf search functions'),
-      'callback'  => 'qbf_query',
-      );
+    if ($form[$childName]['#qbf']['#level'] > QBF_LEVEL_REMOVE)
+      {
+      $arQuery[] = $childName . '=' . $form[$childName]['#value'];
+      }
     }
-
-  return $items;
+  $query = implode(', ', $arQuery);
+  $form['food'] = array
+    (
+    '#type'    => 'markup',
+    '#value'   => "<p>Requête sur $query</p>",
+    );
+  return $form;
   }
-
-function qbf_query($form_id)
-  {
-  dsm("qq $form_id");
-  return "QQ $form_id";
-  }