* based on an idea from chx, from the conversation at * http://www.drupal.org/node/27155 * used to be rest.module, from my sandbox */ // $Id: prepopulate.module,v 1.6 2007-01-28 16:41:36 eafarris Exp $ function prepopulate_help($section) { switch($section) { case 'admin/modules#description': return t('Pre-populates forms for allowed content types with HTTP GET data'); break; } // endswitch $section } // endfunction prepopulate_help() function prepopulate_form_alter($form_id, &$form) { if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { // node type settings form $type = $form['#node_type']->type; $form['workflow']['prepopulate_allowed'] = array( '#type' => 'checkbox', '#title' => 'Prepopulate form from URL?', '#default_value' => variable_get('prepopulate_allowed_' . $type, TRUE), '#description' => t('Allows fields to be prepopulated from the URL'), ); } // endif on a node settings form $type = $form['type']['#value']; if (variable_get('prepopulate_allowed_' . $type, TRUE) && $_GET['edit']) { foreach (array_keys( (array) $_GET['edit']) as $getvar) { if (element_child($getvar) && !is_null($form[$getvar])) { _prepopulate_get_walk($form[$getvar], $_GET['edit'][$getvar]); } } // endforeach get variable } // endif any get vars } // endfunction prepopulate_form_alter() function _prepopulate_get_walk(&$form, &$getslice) { if (!is_array($getslice)) { $form['#default_value'] = $getslice; } else { foreach (array_keys($getslice) as $getvar) { if (element_child($getvar) && is_array($form) && !is_null($form[$getvar])) { _prepopulate_get_walk($form[$getvar], $getslice[$getvar]); } } // endforeach walking through get } // endif getslice is not an array } // endfunction _prepopulate_get_walk() // vim: tw=300 nowrap syn=php