|
@@ -7,7 +7,7 @@
|
|
*
|
|
*
|
|
* @copyright 2008 Ouest Systemes Informatiques (OSInet)
|
|
* @copyright 2008 Ouest Systemes Informatiques (OSInet)
|
|
* @author Frederic G. MARAND
|
|
* @author Frederic G. MARAND
|
|
- * @version $Id: qbf.module,v 1.2 2008-08-25 15:03:33 marand Exp $
|
|
|
|
|
|
+ * @version $Id: qbf.module,v 1.3 2008-08-25 17:40:53 marand Exp $
|
|
* @license CeCILL 2.0
|
|
* @license CeCILL 2.0
|
|
* @package QBF
|
|
* @package QBF
|
|
*/
|
|
*/
|
|
@@ -51,50 +51,28 @@ function qbf_rewrite_form($form)
|
|
* This function obtains the form array using Forms API, and transforms it by
|
|
* This function obtains the form array using Forms API, and transforms it by
|
|
* modifying widgets to other types where needed.
|
|
* modifying widgets to other types where needed.
|
|
*
|
|
*
|
|
- * The $arHooks array contains hooks to be invoked, indexed by hook name, with
|
|
|
|
- * their arguments
|
|
|
|
|
|
+ * Any additional parameter passed to the function is transmitted to the form
|
|
|
|
+ * generating function.
|
|
*
|
|
*
|
|
* @param string $form_id
|
|
* @param string $form_id
|
|
- * @param array $arHooks
|
|
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
-function qbf_transform_form($form_id, $arHooks = array())
|
|
|
|
|
|
+function qbf_transform_form($form_id)
|
|
{
|
|
{
|
|
- // Fetch the basic form and rename it
|
|
|
|
- $form = drupal_retrieve_form($form_id, NULL);
|
|
|
|
|
|
+ $arArgs = func_get_args();
|
|
|
|
+
|
|
|
|
+ // 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";
|
|
$newFormId = "qbf_$form_id";
|
|
|
|
|
|
- // Invoke the optional hooks extending it
|
|
|
|
- foreach ($arHooks as $hookName => $arHookArguments)
|
|
|
|
|
|
+ // Only keep the children of the form and QBF properties on the form itself
|
|
|
|
+ $elements = array();
|
|
|
|
+ $newForm = array();
|
|
|
|
+ if (in_array('#qbf', element_properties($form)))
|
|
{
|
|
{
|
|
- // dsm("Firing $hookName");
|
|
|
|
-
|
|
|
|
- foreach (module_implements($hookName) as $module)
|
|
|
|
- {
|
|
|
|
- $function = $module .'_'. $hookName;
|
|
|
|
- switch ($hookName)
|
|
|
|
- {
|
|
|
|
- case 'form':
|
|
|
|
- // @todo FIXME needs node with type property set
|
|
|
|
- // $formAdditions = node_invoke(new stdClass(), $hookName, $arHookArguments);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- $formAdditions = module_invoke_all($hookName, $arHookArguments);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- // dsm(array($function => $formAdditions));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (is_array($formAdditions))
|
|
|
|
- {
|
|
|
|
- $form = array_merge_recursive($form, $formAdditions);
|
|
|
|
- }
|
|
|
|
|
|
+ $newForm += $form['#qbf'];
|
|
}
|
|
}
|
|
|
|
|
|
- // Only keep the children of the form
|
|
|
|
- $elements = array();
|
|
|
|
- $newForm = array();
|
|
|
|
- $form['mark'] = array('#type' => 'textarea', '#value' => 'goo');
|
|
|
|
foreach (element_children($form) as $key)
|
|
foreach (element_children($form) as $key)
|
|
{
|
|
{
|
|
// dsm("Transforming $key, type " . $form[$key]['#type']);
|
|
// dsm("Transforming $key, type " . $form[$key]['#type']);
|
|
@@ -168,9 +146,15 @@ function _qbf_transform_element($key, array $element)
|
|
|
|
|
|
// Transform type
|
|
// Transform type
|
|
$sourceType = $element['#type'];
|
|
$sourceType = $element['#type'];
|
|
|
|
+ // .. Default transformation
|
|
$destType = array_key_exists($sourceType, $arDefaultTypeTransformations)
|
|
$destType = array_key_exists($sourceType, $arDefaultTypeTransformations)
|
|
? $arDefaultTypeTransformations[$sourceType]
|
|
? $arDefaultTypeTransformations[$sourceType]
|
|
: $sourceType;
|
|
: $sourceType;
|
|
|
|
+ // .. Apply type override
|
|
|
|
+ if (isset($element['#qbf']['#type']))
|
|
|
|
+ {
|
|
|
|
+ $destType = $element['#qbf']['#type'];
|
|
|
|
+ }
|
|
|
|
|
|
if (is_null($destType))
|
|
if (is_null($destType))
|
|
{
|
|
{
|
|
@@ -232,4 +216,38 @@ function _qbf_transform_element($key, array $element)
|
|
|
|
|
|
//dsm(array('key' => $key, 'transformed element' => $ret));
|
|
//dsm(array('key' => $key, 'transformed element' => $ret));
|
|
return $ret;
|
|
return $ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+function qbf_search()
|
|
|
|
+ {
|
|
|
|
+ dsm('qs');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+function qbf_perm()
|
|
|
|
+ {
|
|
|
|
+ $ret = array('use qbf search functions');
|
|
|
|
+ return $ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+function qbf_menu($may_cache)
|
|
|
|
+ {
|
|
|
|
+ $items = array();
|
|
|
|
+
|
|
|
|
+ if ($may_cache)
|
|
|
|
+ {
|
|
|
|
+ $items[] = array
|
|
|
|
+ (
|
|
|
|
+ 'path' => 'qbf/query',
|
|
|
|
+ 'access' => user_access('use qbf search functions'),
|
|
|
|
+ 'callback' => 'qbf_query',
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $items;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+function qbf_query($form_id)
|
|
|
|
+ {
|
|
|
|
+ dsm("qq $form_id");
|
|
|
|
+ return "QQ $form_id";
|
|
}
|
|
}
|