summaryrefslogtreecommitdiff
path: root/includes/common.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/common.inc')
-rw-r--r--includes/common.inc24
1 files changed, 24 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 07422d08d..bebe2ad52 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5602,6 +5602,30 @@ function element_get_visible_children(array $elements) {
}
/**
+ * Sets HTML attributes based on element properties.
+ *
+ * @param $element
+ * The renderable element to process.
+ * @param $map
+ * An associative array whose keys are element property names and whose values
+ * are the HTML attribute names to set for corresponding the property; e.g.,
+ * array('#propertyname' => 'attributename'). If both names are identical
+ * except for the leading '#', then an attribute name value is sufficient and
+ * no property name needs to be specified.
+ */
+function element_set_attributes(array &$element, array $map) {
+ foreach ($map as $property => $attribute) {
+ // If the key is numeric, the attribute name needs to be taken over.
+ if (is_int($property)) {
+ $property = '#' . $attribute;
+ }
+ if (isset($element[$property])) {
+ $element['#attributes'][$attribute] = $element[$property];
+ }
+ }
+}
+
+/**
* Sets a value in a nested array with variable depth.
*
* This helper function should be used when the depth of the array element you