public function LiveWeatherDeleteForm::submitForm in Live Weather 8.2
Same name and namespace in other branches
- 8 src/Form/LiveWeatherDeleteForm.php \Drupal\live_weather\Form\LiveWeatherDeleteForm::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 FormInterface::submitForm
File
- src/
Form/ LiveWeatherDeleteForm.php, line 91 - Contains \Drupal\live_weather\Form\LiveWeatherDeleteForm.
Class
- LiveWeatherDeleteForm
- Builds the form to delete the location.
Namespace
Drupal\live_weather\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$messenger = $this
->messenger();
$locations = $this->configFactory
->get('live_weather.location')
->get('location');
$woeid = $this->woeid;
if (array_key_exists($woeid, $locations)) {
unset($locations[$woeid]);
$this->configFactory
->getEditable('live_weather.location')
->set('location', $locations)
->save();
$form_state
->setRedirect('live_weather.location');
$msg = $this
->t('Your @woeid - Where On Earth IDentifier of location has been removed.', [
'@woeid' => $woeid,
]);
$messenger
->addMessage($msg);
}
else {
$msg = $this
->t('Your @woeid - Where On Earth IDentifier of location is not valid.', [
'@woeid' => $woeid,
]);
$messenger
->addWarning($msg);
}
}