public static function Checkboxes::getCheckedCheckboxes in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Render/Element/Checkboxes.php \Drupal\Core\Render\Element\Checkboxes::getCheckedCheckboxes()
- 9 core/lib/Drupal/Core/Render/Element/Checkboxes.php \Drupal\Core\Render\Element\Checkboxes::getCheckedCheckboxes()
Determines which checkboxes were checked when a form is submitted.
Parameters
array $input: An array returned by the FormAPI for a set of checkboxes.
Return value
array An array of keys that were checked.
2 calls to Checkboxes::getCheckedCheckboxes()
- Checkboxes::detectEmptyCheckboxes in core/
lib/ Drupal/ Core/ Render/ Element/ Checkboxes.php - Determines if all checkboxes in a set are unchecked.
- ViewsExposedForm::submitForm in core/
modules/ views/ src/ Form/ ViewsExposedForm.php - Form submission handler.
File
- core/
lib/ Drupal/ Core/ Render/ Element/ Checkboxes.php, line 158
Class
- Checkboxes
- Provides a form element for a set of checkboxes.
Namespace
Drupal\Core\Render\ElementCode
public static function getCheckedCheckboxes(array $input) {
// Browsers do not include unchecked options in a form submission. The
// FormAPI tries to normalize this to keep checkboxes consistent with other
// form elements. Checkboxes show up as an array in the form of option_id =>
// option_id|0, where integer 0 is an unchecked option.
//
// @see \Drupal\Core\Render\Element\Checkboxes::valueCallback()
// @see https://www.w3.org/TR/html401/interact/forms.html#checkbox
$checked = array_filter($input, function ($value) {
return $value !== 0;
});
return array_keys($checked);
}