You are here

function field_ipaddress_field_widget_form in IP address fields 7

Implements hook_field_widget_form().

File

./field_ipaddress.module, line 127

Code

function field_ipaddress_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'field_ipaddress_long':
      $element += array(
        '#type' => 'fieldset',
        '#element_validate' => array(
          '_field_ipaddress_validate_long',
        ),
      );
      $element['start'] = array(
        '#type' => 'textfield',
        '#title' => t('Start'),
        '#size' => 15,
        '#default_value' => isset($items[$delta]['start']) ? long2ip($items[$delta]['start']) : '',
      );
      $element['end'] = array(
        '#type' => 'textfield',
        '#title' => t('End'),
        '#size' => 15,
        '#default_value' => isset($items[$delta]['end']) ? long2ip($items[$delta]['end']) : '',
      );
      break;
    case 'field_ipaddress_shorthand':
      $element += array(
        '#element_validate' => array(
          '_field_ipaddress_validate_shorthand',
        ),
      );
      $value = isset($items[$delta]['start']) && isset($items[$delta]['end']) ? _field_ipaddress_long2shorthand($items[$delta]['start'], $items[$delta]['end']) : '';
      $element['start'] = array(
        '#type' => 'textfield',
        '#default_value' => $value,
        '#size' => 30,
        '#maxlength' => 100,
      );
      break;
    case 'field_ipaddress_cidr':
      $element += array(
        '#element_validate' => array(
          '_field_ipaddress_validate_cidr',
        ),
      );
      $value = isset($items[$delta]['start']) && isset($items[$delta]['end']) ? _field_ipaddress_long2cidr($items[$delta]['start'], $items[$delta]['end']) : '';
      $element['start'] = array(
        '#type' => 'textfield',
        '#default_value' => $value,
        '#size' => 30,
        '#maxlength' => 100,
      );
      break;
  }
  return $element;
}