You are here

function advpoll_field_field_widget_form in Advanced Poll 7.2

Same name and namespace in other branches
  1. 7.3 advpoll_field/advpoll_field.module \advpoll_field_field_widget_form()
  2. 7 advpoll_field/advpoll_field.module \advpoll_field_field_widget_form()

Implements hook_field_widget_form().

File

advpoll_field/advpoll_field.module, line 81
/*

Code

function advpoll_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $element += array(
    '#delta' => $delta,
  );
  switch ($instance['widget']['type']) {
    case 'advpoll_write_in':
      $element['choice'] = array(
        '#title' => check_plain($element['#title']),
        '#type' => 'textfield',
        '#size' => 110,
        '#default_value' => empty($items[$delta]['choice']) ? '' : $items[$delta]['choice'],
        '#description' => check_plain($element['#description']),
        '#required' => $element['#required'],
      );
      $element['write_in'] = array(
        '#type' => 'checkbox',
        '#title' => t('Write-in (When checked, item will not be displayed for voting until unchecked.)'),
        '#default_value' => empty($items[$delta]['write_in']) ? 0 : 1,
      );
      $default = dechex(time() * rand(5, 50));

      // decided to hex for a smaller value to stick into votingapi tag field. Added a randomized
      // multiplier to make absolutely sure value is unique if choices are created at the same time.
      $element['choice_id'] = array(
        '#type' => 'hidden',
        '#default_value' => empty($items[$delta]['choice_id']) ? $default : $items[$delta]['choice_id'],
      );
  }
  return $element;
}