public static function Dropdown::processDropdown in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.2 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.3 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.4 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.5 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.6 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.7 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 8.8 modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 10.3.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 10.0.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 10.1.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
- 10.2.x modules/custom/dropdown/src/Element/Dropdown.php \Drupal\dropdown\Element\Dropdown::processDropdown()
Expands a radios element into individual radio elements.
File
- modules/
custom/ dropdown/ src/ Element/ Dropdown.php, line 48
Class
- Dropdown
- Provides an dropdown element.
Namespace
Drupal\dropdown\ElementCode
public static function processDropdown(&$element, FormStateInterface $form_state, &$complete_form) {
if (count($element['#options']) > 0) {
$weight = 0;
foreach ($element['#options'] as $key => $option) {
$value = HtmlUtility::escape($option['value']);
$label = HtmlUtility::escape($option['label']);
$description = isset($option['description']) ? HtmlUtility::escape($option['description']) : NULL;
// Maintain order of options as defined in #options, in case the element
// defines custom option sub-elements, but does not define all option
// sub-elements.
$weight += 0.001;
$element += [
$key => [],
];
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($element['#parents'], [
$key,
]);
$element[$key] += [
'#type' => 'radio',
'#title' => $label,
'#description' => $description,
// The key is sanitized in Drupal\Core\Template\Attribute during
// output from the theme function.
'#return_value' => $value,
// Use default or FALSE. A value of FALSE means that the radio button
// is not 'checked'.
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : FALSE,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
// Errors should only be shown on the parent radios element.
'#error_no_message' => TRUE,
'#weight' => $weight,
];
}
}
return $element;
}