function form_type_table_value

Determines the value of a table form element.

Parameters

array $element: The form element whose value is being populated.

array|false $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.

Return value

array The data that will appear in the $form_state['values'] collection for this element. Return nothing to use the default.

Related topics

1 string reference to 'form_type_table_value'
system_element_info in drupal/core/modules/system/system.module
Implements hook_element_info().

File

drupal/core/includes/form.inc, line 2401
Functions for form and batch generation and processing.

Code

function form_type_table_value(array $element, $input = FALSE) {

  // 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 += array(
        '#default_value' => array(),
      );
      return drupal_map_assoc(array_keys(array_filter($element['#default_value'])));
    }
    else {
      return is_array($input) ? drupal_map_assoc($input) : array();
    }
  }
}