function advpoll_field_field_widget_form in Advanced Poll 7
Same name and namespace in other branches
- 7.3 advpoll_field/advpoll_field.module \advpoll_field_field_widget_form()
- 7.2 advpoll_field/advpoll_field.module \advpoll_field_field_widget_form()
Implements hook_field_widget_form().
File
- advpoll_field/
advpoll_field.module, line 78 - Provides a FieldAPI field type for presenting an Advanced Poll choice field with a Boolean checkbox to indicate write-in status.
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' => $element['#title'],
'#type' => 'textfield',
'#size' => 110,
'#default_value' => empty($items[$delta]['choice']) ? '' : $items[$delta]['choice'],
'#description' => $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;
}