public function SettingsForm::buildForm in Voting API 8.3
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ SettingsForm.php, line 67
Class
- SettingsForm
- A form used to configure Voting API settings.
Namespace
Drupal\votingapi\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('votingapi.settings');
$unit_options = [
300,
900,
1800,
3600,
10800,
21600,
32400,
43200,
86400,
172800,
345600,
604800,
];
$options[0] = 'Immediately';
foreach ($unit_options as $option) {
$options[$option] = $this->dateFormatter
->formatInterval($option);
}
$options[-1] = 'Never';
$form['anonymous_window'] = [
'#type' => 'select',
'#title' => $this
->t('Anonymous vote rollover'),
'#description' => $this
->t("The amount of time that must pass before two anonymous votes from the same computer are considered unique. Setting this to 'never' will eliminate most double-voting, but will make it impossible for multiple anonymous on the same computer (like internet cafe customers) from casting votes."),
'#options' => $options,
'#default_value' => $config
->get('anonymous_window'),
];
$form['user_window'] = [
'#type' => 'select',
'#title' => $this
->t('Registered user vote rollover'),
'#description' => $this
->t("The amount of time that must pass before two registered user votes from the same user ID are considered unique. Setting this to 'never' will eliminate most double-voting for registered users."),
'#options' => $options,
'#default_value' => $config
->get('user_window'),
];
$form['calculation_schedule'] = [
'#type' => 'radios',
'#title' => $this
->t('Calculation schedule'),
'#description' => $this
->t('On high-traffic sites, administrators can use this setting to postpone the calculation of vote results.'),
'#default_value' => $config
->get('calculation_schedule'),
'#options' => [
'immediate' => $this
->t('Tally results whenever a vote is cast'),
'cron' => $this
->t('Tally results at cron-time'),
'manual' => $this
->t('Do not tally results automatically: I am using a module that manages its own vote results.'),
],
'#required' => TRUE,
];
$form['delete_everywhere'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Delete everywhere'),
'#description' => $this
->t("Allow deleting votes to someone else's entity when owner user of this votes is deleting."),
'#default_value' => $config
->get('delete_everywhere'),
];
return parent::buildForm($form, $form_state);
}