You are here

function double_field_field_widget_form in Double Field 7

Same name and namespace in other branches
  1. 7.2 double_field.module \double_field_field_widget_form()

Implements hook_field_widget_form().

File

./double_field.module, line 163
Defines double text field type.

Code

function double_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $settings = $instance['widget']['settings'];
  $double_field = array(
    '#theme_wrappers' => array(
      'form_element',
    ),
  );
  foreach (array(
    'first',
    'second',
  ) as $subfield) {
    $double_field[$subfield] = array(
      '#type' => 'textfield',
      '#prefix' => $settings[$subfield]['prefix'],
      '#suffix' => $settings[$subfield]['suffix'],
      '#default_value' => isset($items[$delta][$subfield]) ? $items[$delta][$subfield] : NULL,
      '#size' => $settings[$subfield]['size'],
      '#maxlength' => $field['settings'][$subfield . '_maxlength'],
    );
  }
  if ($settings['inline']) {
    $double_field['first']['#prefix'] = '<div class="container-inline">' . $double_field['first']['#prefix'];
    $double_field['second']['#suffix'] .= '</div>';
  }
  return $element + $double_field;
}