You are here

public function LiveWeatherDeleteForm::submitForm in Live Weather 8

Same name and namespace in other branches
  1. 8.2 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 81
Contains \Drupal\live_weather\Form\LiveWeatherDeleteForm.

Class

LiveWeatherDeleteForm
Builds the form to delete the location.

Namespace

Drupal\live_weather\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $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');
    drupal_set_message($this
      ->t('Your @woeid - Where On Earth IDentification of location remvoed', array(
      '@woeid' => $woeid,
    )));
  }
  else {
    drupal_set_message($this
      ->t('Your @woeid - Where On Earth IDentification of location is not valid', array(
      '@woeid' => $woeid,
    )));
  }
}