function BooleanCheckboxWidget::formElement
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\BooleanCheckboxWidget::formElement()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\BooleanCheckboxWidget::formElement()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\BooleanCheckboxWidget::formElement()
Overrides WidgetInterface::formElement
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ BooleanCheckboxWidget.php, line 59
Class
- BooleanCheckboxWidget
- Plugin implementation of the 'boolean_checkbox' widget.
Namespace
Drupal\Core\Field\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + [
'#type' => 'checkbox',
'#default_value' => !empty($items[0]->value),
];
// Override the title from the incoming $element.
if ($this->getSetting('display_label')) {
$element['value']['#title'] = $this->fieldDefinition
->getLabel();
}
else {
$element['value']['#title'] = $this->fieldDefinition
->getSetting('on_label');
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.