You are here

function itoggle_field_widget_form in iToggle 7

Implements hook_field_widget_form().

File

modules/field/itoggle_field.module, line 76
iToggle Field module.

Code

function itoggle_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $type = $instance['widget']['type'];
  $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
  $required = $element['#required'];
  $has_value = isset($items[0]['value']);
  $keys = array_keys($field['settings']['allowed_values']);
  $off_value = array_shift($keys);
  $on_value = array_shift($keys);
  $element += array(
    '#type' => 'checkbox',
    '#default_value' => $has_value ? $has_value : $instance['default_value'][0]['value'],
    '#on_value' => $on_value,
    '#off_value' => $off_value,
    '#title' => $instance['label'],
    '#element_validate' => array(
      'itoggle_field_widget_validate',
    ),
    '#value_key' => 'value',
  );
  return $element;
}