function Table::validateTable
Same name in other branches
- 9 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::validateTable()
- 8.9.x core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::validateTable()
- 10 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::validateTable()
#element_validate callback for #type 'table'.
Parameters
array $element: An associative array containing the properties and children of the table element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ Table.php, line 309
Class
- Table
- Provides a render element for a table.
Namespace
Drupal\Core\Render\ElementCode
public static function validateTable(&$element, FormStateInterface $form_state, &$complete_form) {
// Skip this validation if the button to submit the form does not require
// selected table row data.
$triggering_element = $form_state->getTriggeringElement();
if (empty($triggering_element['#tableselect'])) {
return;
}
if ($element['#multiple']) {
if (!is_array($element['#value']) || !count(array_filter($element['#value']))) {
$form_state->setError($element, t('No items selected.'));
}
}
elseif (!isset($element['#value']) || $element['#value'] === '') {
$form_state->setError($element, t('No item selected.'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.