1 form.inc | theme_container($variables) |
Returns HTML to wrap child elements in a container.
Used for grouped form items. Can also be used as a theme wrapper for any renderable element, to surround it with a <div> and add attributes such as classes or an HTML id.
theme_container() also handles 'checkboxes' and 'radios' elements. See: https://docs.backdropcms.org/change-records/functions-theme_radios-and-t...
See the Form API reference for more information on the #theme_wrappers render array property.
Parameters
$variables: An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #id, #attributes, #children.
Related topics
File
- core/
includes/ form.inc, line 3685 - Functions for form and batch generation and processing.
Code
function theme_container($variables) {
$element = $variables['element'];
// Ensure #attributes is set, while preserving any existing attribute(s).
$element += array('#attributes' => array());
// Special handling for form elements.
if (isset($element['#array_parents'])) {
// Assign an HTML ID.
if (!array_key_exists('id', $element['#attributes'])) {
$element['#attributes']['id'] = $element['#id'];
}
// Add the 'form-wrapper' class if not already added, but only for
// 'container' elements. theme_container() also handles 'checkboxes' and
// 'radios' elements, but #states breaks for them if the 'form-wrapper'
// class is added.
if (isset($element['#type']) && $element['#type'] == 'container') {
// Ensure that the class attribute is set, while preserving any existing
// classes.
$element['#attributes'] += array('class' => array());
if (!in_array('form-wrapper', $element['#attributes']['class'])) {
$element['#attributes']['class'][] = 'form-wrapper';
}
}
}
if (isset($element['#indentation'])) {
// Ensure that the class attribute is set, while preserving any existing
// classes.
$element['#attributes'] += array('class' => array());
$element['#attributes']['class'][] = 'form-item-indentation';
$element['#attributes']['class'][] = 'form-item-indentation-' . $element['#indentation'];
$element['#attributes']['data-indentation-depth'] = $element['#indentation'];
}
return '<div' . backdrop_attributes($element['#attributes']) . '>' . $element['#children'] . '</div>';
}