function element_set_attributes in Elements 6
Sets HTML attributes based on element properties.
This is a backport from the Drupal 7 core function of the same name.
@parm $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.
Parameters
$element: The renderable element to process.
6 calls to element_set_attributes()
- theme_emailfield in ./
elements.theme.inc - Returns HTML for an emailfield form element.
- theme_numberfield in ./
elements.theme.inc - Returns HTML for a numberfield form element.
- theme_rangefield in ./
elements.theme.inc - Returns HTML for a rangefield form element.
- theme_searchfield in ./
elements.theme.inc - Returns HTML for a searchfield form element.
- theme_telfield in ./
elements.theme.inc - Returns HTML for a telfield form element.
File
- ./
elements.module, line 167
Code
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;
}
// Do not overwrite already existing attributes.
if (isset($element[$property]) && !isset($element['#attributes'][$attribute])) {
$element['#attributes'][$attribute] = $element[$property];
}
}
}