function element_set_attributes

Sets HTML attributes based on element properties.

Parameters

$element: The renderable element to process.

$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.

22 calls to element_set_attributes()
drupal_pre_render_table in drupal/core/includes/theme.inc
#pre_render callback to transform children of an element into #rows suitable for theme_table().
form_pre_render_button in drupal/core/includes/form.inc
Prepares a #type 'button' render element for theme_input().
form_pre_render_checkbox in drupal/core/includes/form.inc
Prepares a #type 'checkbox' render element for theme_input().
form_pre_render_color in drupal/core/includes/form.inc
Prepares a #type 'color' render element for theme_input().
form_pre_render_email in drupal/core/includes/form.inc
Prepares a #type 'email' render element for theme_input().

... See full list

File

drupal/core/includes/common.inc, line 5421
Common functions that many Drupal modules will need to reference.

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];
    }
  }
}