protected static function ElementBase::addOtherField in Select (or other) 8
Same name and namespace in other branches
- 4.x src/Element/ElementBase.php \Drupal\select_or_other\Element\ElementBase::addOtherField()
Adds the 'other' field to the element.
Parameters
array $element: The select or other element.
1 call to ElementBase::addOtherField()
- ElementBase::processSelectOrOther in src/
Element/ ElementBase.php - Render API callback: Expands the select_or_other element type.
File
- src/
Element/ ElementBase.php, line 138
Class
- ElementBase
- Base class for select or other form elements.
Namespace
Drupal\select_or_other\ElementCode
protected static function addOtherField(array &$element) {
$element['other'] = [
'#type' => 'textfield',
'#attributes' => [
'aria-label' => isset($element['#title']) ? $element['#title'] . ' Other' : $element['#name'] . ' Other',
],
'#weight' => 20,
'#attributes' => [
'placeholder' => t('Other: please specify here'),
],
];
if (isset($element['#other_options'])) {
$element['other']['#default_value'] = $element['#other_options'];
}
}