public function AutobanFormBase::save in Automatic IP ban (Autoban) 8
Overrides Drupal\Core\Entity\EntityFormController::save().
Saves the entity. This is called after submit() has built the entity from the form values. Do not override submit() as save() is the preferred method for entity form controllers.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.
Overrides EntityForm::save
File
- src/
Form/ AutobanFormBase.php, line 351 - Class AutobanFormBase.
Class
- AutobanFormBase
- Autoban base form for add and edit.
Namespace
Drupal\autoban\FormCode
public function save(array $form, FormStateInterface $form_state) {
$last_threshold = $form_state
->getValue('threshold');
$last_provider = $form_state
->getValue('provider');
$this->config
->getEditable('autoban.settings')
->set('autoban_threshold_last', $last_threshold)
->set('autoban_provider_last', $last_provider)
->save();
$autoban = $this
->getEntity();
$status = $autoban
->save();
$url = $autoban
->toUrl();
$edit_link = Link::fromTextAndUrl($this
->t('Edit'), $url)
->toString();
if ($status == SAVED_UPDATED) {
// If we edited an existing entity...
$this
->messenger()
->addMessage($this
->t('Autoban rule %label has been updated.', [
'%label' => $autoban
->id(),
]));
$this
->logger('autoban')
->notice('Autoban rule %label has been updated.', [
'%label' => $autoban
->id(),
'link' => $edit_link,
]);
}
else {
// If we created a new entity...
$this
->messenger()
->addMessage($this
->t('Autoban rule %label has been added.', [
'%label' => $autoban
->id(),
]));
$this
->logger('autoban')
->notice('Autoban rule %label has been added.', [
'%label' => $autoban
->id(),
'link' => $edit_link,
]);
}
// Redirect the user back to the listing route after the save operation.
$form_state
->setRedirect('entity.autoban.list');
}