function template_preprocess_dropdown in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.2 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.3 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.4 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.5 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.6 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.7 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 8.8 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 10.3.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 10.0.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
- 10.1.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
Prepares variables for dropdown templates.
Default template: dropdown.html.twig.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes, #children.
File
- modules/
custom/ dropdown/ dropdown.module, line 50 - Contains dropdown.module.
Code
function template_preprocess_dropdown(array &$variables) {
$element = $variables['element'];
$variables['attributes'] = [];
if (isset($element['#id'])) {
$variables['attributes']['id'] = $element['#id'];
}
if (isset($element['#attributes']['title'])) {
$variables['attributes']['title'] = $element['#attributes']['title'];
}
$items = [];
foreach ($element as $key => $el) {
if (is_numeric($key) && isset($el['#type']) && $el['#type'] === 'radio') {
$items[$key] = $el;
if ($el['#return_value'] === $el['#value']) {
// @todo Do we need to check for default_value also
$selected = Html::escape($el['#title']);
$active = $key;
}
}
}
if (isset($element['#edit_mode'])) {
$variables['edit_mode'] = $element['#edit_mode'];
}
$variables['items'] = $items;
$variables['label'] = Html::escape($element['#title']);
$variables['selected'] = isset($selected) ? $selected : $variables['label'];
$variables['active'] = isset($active) ? $active : 0;
$variables['children'] = $element['#children'];
}