public function RateSettingsForm::submitForm in Rate 8
Same name and namespace in other branches
- 8.2 src/Form/RateSettingsForm.php \Drupal\rate\Form\RateSettingsForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ RateSettingsForm.php, line 242
Class
- RateSettingsForm
- Configure rate settings for the site.
Namespace
Drupal\rate\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('rate.settings');
$enabled_rate_widgets = [];
$enabled_types_widgets = [];
$values = $form_state
->getValues();
$enabled_rate_widgets = $form_state
->getValue('enabled_rate_widgets');
foreach ($enabled_rate_widgets as $index => $value) {
if (!empty($value['widget_type'])) {
if (stripos($index, 'enabled|') !== FALSE && $value) {
$entity_bundle = explode('|', str_ireplace('enabled|', '', $index));
if (isset($enabled_types_widgets[$entity_bundle[0]])) {
$enabled_types_widgets[$entity_bundle[0]][$entity_bundle[1]] = [
'widget_type' => $value['widget_type'],
'use_ajax' => $form_state
->getValue('use_ajax'),
];
}
else {
$enabled_types_widgets[$entity_bundle[0]] = [];
$enabled_types_widgets[$entity_bundle[0]][$entity_bundle[1]] = [
'widget_type' => $value['widget_type'],
'use_ajax' => $form_state
->getValue('use_ajax'),
];
}
}
}
else {
unset($enabled_types_widgets[$index]);
}
}
$config
->set('enabled_types_widgets', $enabled_types_widgets)
->set('bot_minute_threshold', $form_state
->getValue('bot_minute_threshold'))
->set('bot_hour_threshold', $form_state
->getValue('bot_hour_threshold'))
->set('botscout_key', $form_state
->getValue('botscout_key'))
->set('use_ajax', $form_state
->getValue('use_ajax'))
->save();
parent::submitForm($form, $form_state);
}