| 1 |
<?php |
<?php |
| 2 |
// $Id: prepopulate.module,v 1.10 2008/05/03 18:04:54 add1sun Exp $ |
// $Id: prepopulate.module,v 1.10.2.1 2008/11/17 17:41:28 add1sun Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 16 |
function prepopulate_help($path, $arg) { |
function prepopulate_help($path, $arg) { |
| 17 |
switch ($path) { |
switch ($path) { |
| 18 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 19 |
return t('Prepopulates forms for allowed content types with HTTP GET data'); |
return t('Pre-populates forms with HTTP GET data'); |
| 20 |
break; |
break; |
| 21 |
} |
} |
| 22 |
} |
} |
| 25 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 26 |
*/ |
*/ |
| 27 |
function prepopulate_form_alter(&$form, $form_state, $form_id) { |
function prepopulate_form_alter(&$form, $form_state, $form_id) { |
| 28 |
switch ($form_id) { |
if (isset($_GET['edit'])) { |
| 29 |
// Add our checkbox to the content type edit forms |
foreach (array_keys((array)$_GET['edit']) as $getvar) { |
| 30 |
// (admin/content/node-type/$type). |
if (element_child($getvar) && !is_null($form[$getvar])) { |
| 31 |
case 'node_type_form': |
_prepopulate_get_walk($form[$getvar], $_GET['edit'][$getvar]); |
|
$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'), |
|
|
); |
|
|
return; |
|
|
} |
|
|
|
|
|
// Process the URL on a node add/edit form (node/add/$type). |
|
|
if (isset($form['#node'])) { |
|
|
$node = $form['#node']; |
|
|
// Make sure this node type allows prepopulate and |
|
|
// that we have a $_GET variable in the URL. |
|
|
if (variable_get('prepopulate_allowed_'. $node->type, TRUE) && isset($_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]); |
|
|
} |
|
| 32 |
} |
} |
| 33 |
} |
} |
| 34 |
} |
} |