You are here

public static function Table::validateTable in Drupal 9

Same name and namespace in other branches
  1. 8 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 257

Class

Table
Provides a render element for a table.

Namespace

Drupal\Core\Render\Element

Code

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.'));
  }
}