type = 'poll'; $arFuncs1 = node_forms(); //dsm($arFuncs1); $form = node_form($node, array('qbe-key' => 'qbe-value')); //dsm($form); return 'foo'; } function qbf_rewrite_form($form) { $hookName = 'qbf_rewrite_form'; foreach (module_implements($hookName) as $module) { $function = "${module}_$hookName"; $form = $function($form); } return drupal_get_form($form); } /** * Transform a form array for QBF * * This function obtains the form array using Forms API, and transforms it by * modifying widgets to other types where needed. * * Any additional parameter passed to the function is transmitted to the form * generating function. * * @param string $form_id * @return array */ function qbf_transform_form($form_id) { $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"; // 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))) { $newForm += $form['#qbf']; } foreach (element_children($form) as $key) { // dsm("Transforming $key, type " . $form[$key]['#type']); $newElement = _qbf_transform_element($key, $form[$key]); if (!is_null($newElement)) { $newForm[$key] = $newElement; } } $newForm['#id'] = $newFormId; // dsm($newForm); return $newForm; } /** * Transform a form element for QBF * * QBF-specific properties are: * - #qbf : array of properties * - #level: only within #qbf @see QBF_* constants * * @param array &$element * @return void */ function _qbf_transform_element($key, array $element) { // dsm(array('key' => $key, 'element' => $element)); // Types without a default transformation are not transformed static $arDefaultTypeTransformations = array ( 'button' => NULL, 'file' => NULL, 'hidden' => NULL, 'markup' => NULL, 'password' => NULL, 'radio' => NULL, 'submit' => NULL, 'textarea' => 'textfield', 'value' => NULL, ); // Properties without a default transformation are not transformed static $arDefaultPropertyTransformations = array ( // Standard properties '#action' => NULL, '#after_build' => NULL, '#base' => NULL, '#button_type' => NULL, '#built' => NULL, '#description' => NULL, '#method' => NULL, '#parents' => NULL, '#redirect' => NULL, '#ref' => NULL, '#required' => NULL, '#rows' => NULL, '#submit' => NULL, '#tree' => NULL, '#validate' => NULL, '#value' => NULL, ); // Property values causing element removal static $arKillerProperties = array ( '#disabled' => TRUE, ); // Transform type $sourceType = $element['#type']; // .. Default transformation $destType = array_key_exists($sourceType, $arDefaultTypeTransformations) ? $arDefaultTypeTransformations[$sourceType] : $sourceType; // .. Apply type override if (isset($element['#qbf']['#type'])) { $destType = $element['#qbf']['#type']; } if (is_null($destType)) { $ret = NULL; } else { $ret = $element; $ret['#type'] = $destType; if (!array_key_exists('#qbf', $element) || $element['#qbf']['#level'] == QBF_LEVEL_REMOVE) { $ret = NULL; } else { foreach (element_properties($element) as $propertyName) { // Apply killer properties first to avoid useless work if (array_key_exists($propertyName, $arKillerProperties) && ($element[$propertyName] = $arKillerProperties[$propertyName])) { $ret = NULL; break; } // Now transform or copy remaining properties if (array_key_exists($propertyName, $arDefaultPropertyTransformations)) { $ret[$propertyName] = $arDefaultPropertyTransformations[$propertyName]; } else { $ret[$propertyName] = $element[$propertyName]; } // And apply form-defined overrides if ($propertyName == '#qbf') { foreach ($element[$propertyName] as $overrideName => $overrideValue) { $ret[$overrideName] = $overrideValue; } } } foreach (element_children($element) as $childName) { $child = _qbf_transform_element($childName, $element[$childName]); if (is_null($child)) { unset($ret[$childName]); } else { $ret[$childName] = $child; } } } } //dsm(array('key' => $key, 'transformed element' => $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"; }