summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-12-29 00:19:58 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-12-29 00:19:58 +0000
commitbc82525c95b42207160365d6c6743cce79a43c47 (patch)
treee6b041638ee0f2c0abc111ed313e87959c58e546 /includes
parent2d6f76ce7cfa4598fe1ce78dbebe0baf4130889d (diff)
downloadbrdo-bc82525c95b42207160365d6c6743cce79a43c47.tar.gz
brdo-bc82525c95b42207160365d6c6743cce79a43c47.tar.bz2
#24023 (follow up): Add API function for dealing with form API #options arrays.
Diffstat (limited to 'includes')
-rw-r--r--includes/form.inc21
1 files changed, 21 insertions, 0 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 4c95ce22a..4aac8d1a9 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -942,6 +942,27 @@ function form_select_options($element, $choices = NULL) {
}
/**
+ * Traverses a select element's #option array looking for the object that
+ * holds the given key. Returns FALSE if not found. As usual with functions
+ * that can return 0 or FALSE do not forget to use === and !== if needed.
+ *
+ * @param $element
+ * The select element.
+ * @param $key
+ * The key to look for.
+ * @return
+ * The index of the object that held the $key with some value, or FALSE.
+ */
+function form_get_option_key($element, $key) {
+ foreach ($element['#options'] as $index => $object) {
+ if (isset($object->option[$key])) {
+ return $index;
+ }
+ }
+ return FALSE;
+}
+
+/**
* Format a group of form items.
*
* @param $element