function advpoll_form_alter in Advanced Poll 6.2
Same name and namespace in other branches
- 5 advpoll.module \advpoll_form_alter()
- 6.3 advpoll.module \advpoll_form_alter()
- 6 advpoll.module \advpoll_form_alter()
- 7.3 advpoll.module \advpoll_form_alter()
- 7 advpoll.module \advpoll_form_alter()
- 7.2 advpoll.module \advpoll_form_alter()
Implementation of hook_form_alter().
File
- ./
advpoll.module, line 573 - Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.
Code
function advpoll_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$node_type = $form['old_type']['#value'];
// Display poll settings if this is an advpoll content type.
if ($form['module']['#value'] == 'advpoll') {
// Include JS and CSS for the show_writeins setting toggle.
drupal_add_js(drupal_get_path('module', 'advpoll') . '/advpoll-form.js', 'module');
drupal_add_css(drupal_get_path('module', 'advpoll') . '/advpoll.css', 'module');
$form['advpoll'] = array(
'#type' => 'fieldset',
'#title' => t('Poll settings'),
'#collapsible' => TRUE,
);
$form['advpoll']['advpoll_choices'] = array(
'#type' => 'textarea',
'#title' => t('Default choices'),
'#default_value' => variable_get('advpoll_choices_' . $node_type, ''),
'#description' => t('Add one choice per row. This setting can be overridden on the poll edit page.'),
);
$form['advpoll']['advpoll_max_choices'] = array(
'#type' => 'select',
'#title' => t('Default maximum choices'),
'#options' => array(
0 => t('No limit'),
) + drupal_map_assoc(array(
1,
2,
3,
4,
5,
)),
'#default_value' => variable_get('advpoll_max_choices_' . $node_type, ADVPOLL_MAX_CHOICES),
'#description' => t('The default number of maximum choices for new polls. This setting can be overridden on the poll edit page.'),
);
$mode = _advpoll_get_mode($node_type);
$voting_algorithms = advpoll_algorithms($mode);
if (count($voting_algorithms) > 1) {
$form['advpoll']['advpoll_algorithm'] = array(
'#type' => 'select',
'#title' => t('Default algorithm'),
'#options' => $voting_algorithms,
'#default_value' => variable_get('advpoll_algorithm_' . $node_type, key($voting_algorithms)),
'#description' => t('Default voting algorithm for calculating the winner.'),
);
}
$form['advpoll']['advpoll_runtime'] = array(
'#type' => 'select',
'#title' => t('Default duration'),
'#default_value' => variable_get('advpoll_runtime_' . $node_type, ADVPOLL_RUNTIME),
'#options' => array(
0 => t('Unlimited'),
) + drupal_map_assoc(array(
86400,
172800,
345600,
604800,
1209600,
1814400,
2419200,
4838400,
9676800,
31536000,
), 'format_interval'),
'#description' => t('The date the poll was created is used as start date for the default duration. This setting can be overridden on the poll edit page.'),
);
$form['advpoll']['advpoll_writeins'] = array(
'#type' => 'checkbox',
'#title' => t('Allow users to cast a write-in vote by default'),
'#default_value' => variable_get('advpoll_writeins_' . $node_type, ADVPOLL_WRITEINS),
'#description' => t('Allow voters with the "add write-ins" permission to write-in up to one choice each. Users with the <em>administer polls</em> permission will be able to override this setting.'),
'#attributes' => array(
'class' => 'settings-writeins',
),
);
$form['advpoll']['advpoll_show_writeins'] = array(
'#type' => 'checkbox',
'#title' => t('Display write-in votes as choices for future voters by default'),
'#default_value' => variable_get('advpoll_show_writeins_' . $node_type, ADVPOLL_SHOW_WRITEINS),
'#description' => t("Allow voters to see and choose from previous voters' write-in votes. Users with the <em>administer polls</em> permission will be able to override this setting."),
'#prefix' => '<div class="edit-settings-show-writeins">',
'#suffix' => '</div>',
);
$form['advpoll']['advpoll_electoral_list'] = array(
'#type' => 'checkbox',
'#title' => t('Use electoral list by default'),
'#description' => t('Use an electoral list by default for new polls. Users with the <em>administer polls</em> permission will be able to override this setting.'),
'#default_value' => variable_get('advpoll_electoral_list_' . $node_type, ADVPOLL_ELECTORAL_LIST),
);
$form['advpoll']['advpoll_show_votes'] = array(
'#type' => 'checkbox',
'#title' => t('Show individual votes by default'),
'#description' => t('Let users with appropriate permissions see how each person voted by default for new polls. Users with the <em>administer polls</em> permission will be able to override this setting.'),
'#default_value' => variable_get('advpoll_show_votes_' . $node_type, ADVPOLL_SHOW_VOTES),
);
$view_results = array(
'always' => t('Always'),
'aftervote' => t('After user has voted'),
'afterclose' => t('After voting has closed'),
);
$form['advpoll']['advpoll_view_results'] = array(
'#type' => 'radios',
'#title' => t('Display results'),
'#description' => t('Determines when users may view the results of the poll.'),
'#default_value' => variable_get('advpoll_view_results_' . $node_type, ADVPOLL_VIEW_RESULTS),
'#options' => $view_results,
);
$form['advpoll']['advpoll_use_question'] = array(
'#type' => 'checkbox',
'#title' => t('Use question field'),
'#description' => t('Use a dedicated question field instead of a combined question and title field. It is recommended to rename <em>Title field label</em> above to "Title" if this is checked.'),
'#default_value' => variable_get('advpoll_use_question_' . $node_type, ADVPOLL_USE_QUESTION),
);
}
}
}