function Table::valueCallback

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::valueCallback()
  2. 10 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::valueCallback()
  3. 11.x core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table::valueCallback()

Overrides FormElement::valueCallback

1 method overrides Table::valueCallback()
Tableselect::valueCallback in core/lib/Drupal/Core/Render/Element/Tableselect.php
Determines how user input is mapped to an element's #value property.

File

core/lib/Drupal/Core/Render/Element/Table.php, line 102

Class

Table
Provides a render element for a table.

Namespace

Drupal\Core\Render\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
    // If #multiple is FALSE, the regular default value of radio buttons is used.
    if (!empty($element['#tableselect']) && !empty($element['#multiple'])) {
        // Contrary to #type 'checkboxes', the default value of checkboxes in a
        // table is built from the array keys (instead of array values) of the
        // #default_value property.
        // @todo D8: Remove this inconsistency.
        if ($input === FALSE) {
            $element += [
                '#default_value' => [],
            ];
            $value = array_keys(array_filter($element['#default_value']));
            return array_combine($value, $value);
        }
        else {
            return is_array($input) ? array_combine($input, $input) : [];
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.