diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-11-18 13:48:09 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-11-18 13:48:09 +0000 |
commit | f852db82dc331a24f0925b1e1f7280683b635f85 (patch) | |
tree | 4c3998749f9f5bcc03680721ddc3bc6317e0d8c7 | |
parent | f69503aa584576d6a8bf46516a1c2ed5aa7369c6 (diff) | |
download | brdo-f852db82dc331a24f0925b1e1f7280683b635f85.tar.gz brdo-f852db82dc331a24f0925b1e1f7280683b635f85.tar.bz2 |
- Patch #37915 by chx: improved readability of forms API.
-rw-r--r-- | includes/form.inc | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/includes/form.inc b/includes/form.inc index a32d14259..72a6463cf 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -224,8 +224,12 @@ function _form_builder($form_id, $form) { } if ($form['#input']) { - $form['#name'] = ($form['#name']) ? $form['#name'] : 'edit[' . implode('][', $form['#parents']) . ']'; - $form['#id'] = ($form['#id']) ? $form['#id'] : 'edit-' . implode('-', $form['#parents']); + if (!isset($form['#name'])) { + $form['#name'] = 'edit[' . implode('][', $form['#parents']) . ']'; + } + if (!isset($form['#id'])) { + $form['#id'] = 'edit-' . implode('-', $form['#parents']); + } $posted = (isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id)); $edit = $posted ? $_POST['edit'] : array(); @@ -266,34 +270,37 @@ function _form_builder($form_id, $form) { $count = 0; foreach (element_children($form) as $key) { // don't squash an existing tree value - $form[$key]['#tree'] = (isset($form[$key]['#tree'])) ? $form[$key]['#tree'] : $form['#tree']; + if (!isset($form[$key]['#tree'])) { + $form[$key]['#tree'] = $form['#tree']; + } - if ($form[$key]['#tree']) { - if (!$form['#tree']) { - // begin tree - $parents = array($key); + // don't squash existing parents value + if (!isset($form[$key]['#parents'])) { + if ($form[$key]['#tree']) { + if (!$form['#tree']) { + // begin tree + $form[$key]['#parents'] = array($key); + } + else { + //continue tree + $form[$key]['#parents'] = array_merge($form['#parents'], array($key)); + } } else { - //continue tree - $parents = (array) $form['#parents']; - array_push($parents, $key); + // no tree + $form[$key]['#parents'] = array($key); } } - else { - // no tree - $parents = array($key); - } - - // don't squash existing parents value - $form[$key]['#parents'] = (isset($form[$key]['#parents'])) ? $form[$key]['#parents'] : $parents; # Assign a decimal placeholder weight, to preserve original array order - $form[$key]['#weight'] = $form[$key]['#weight'] ? $form[$key]['#weight'] : $count/1000; + if (!isset($form[$key]['#weight'])) { + $form[$key]['#weight'] = $count/1000; + } $form[$key] = _form_builder($form_id, $form[$key]); $count++; } - if (function_exists($form['#post_process']) && !$form['#post_processed']) { + if (function_exists($form['#post_process']) && !isset($form['#post_processed'])) { $form = call_user_func($form['#post_process'], $form_id, $form, $form_values, $form['#parents']); $form['#post_processed'] = TRUE; } |