public function WeatherDisplayDeleteForm::submitForm in Weather 8
Same name and namespace in other branches
- 2.0.x src/Form/WeatherDisplayDeleteForm.php \Drupal\weather\Form\WeatherDisplayDeleteForm::submitForm()
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.
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 ContentEntityForm::submitForm
File
- src/
Form/ WeatherDisplayDeleteForm.php, line 84
Class
- WeatherDisplayDeleteForm
- Provides a form for deleting a weather_display entity.
Namespace
Drupal\weather\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$display_type = $this->entity->type->value;
$display_number = $this->entity->number->value;
$this->entity
->delete();
$this
->messenger()
->addStatus($this
->t('Weather display was removed.'));
switch ($display_type) {
case WeatherDisplayInterface::USER_TYPE:
$form_state
->setRedirectUrl(Url::fromRoute('weather.user.settings', [
'user' => $display_number,
]));
break;
default:
$form_state
->setRedirectUrl(Url::fromRoute('weather.settings'));
break;
}
$this->block_manager
->clearCachedDefinitions();
parent::submitForm($form, $form_state);
}