You are here

public function VotingApiField::fieldSettingsForm in Votingapi Widgets 8

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::fieldSettingsForm

File

src/Plugin/Field/FieldType/VotingApiField.php, line 142

Class

VotingApiField
Plugin implementation of the 'voting_api_field' field type.

Namespace

Drupal\votingapi_widgets\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $dateFormatter = \Drupal::service('date.formatter');
  $form = parent::fieldSettingsForm($form, $form_state);
  $unit_options = [
    300,
    900,
    1800,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
    172800,
    345600,
    604800,
  ];
  $unit_options_form = [];
  foreach ($unit_options as $option) {
    $unit_options_form[$option] = $dateFormatter
      ->formatInterval($option);
  }
  $unit_options_form[0] = $this
    ->t('never');
  $unit_options_form[-1] = $this
    ->t('votingapi default');
  $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' => $unit_options_form,
    '#default_value' => $this
      ->getSetting('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' => $unit_options_form,
    '#default_value' => $this
      ->getSetting('user_window'),
  ];
  return $form;
}