Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Table.php

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal