You are here

public function GoogleAdwordsPathCodeForm::submitForm in Google AdWords Conversion Tracking 8

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

modules/google_adwords_path/src/Form/GoogleAdwordsPathCodeForm.php, line 119
Contains \Drupal\google_adwords_path\Form\GoogleAdwordsPathCodeForm.

Class

GoogleAdwordsPathCodeForm

Namespace

Drupal\google_adwords_path\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state['clicked_button']['#value'] == 'Save') {
    $form_state
      ->cleanValues();
    google_adwords_path_save_code($form_state
      ->getValues());

    // Updating an existing conversion code.
    if (isset($form_state
      ->getValues()['cid'])) {
      $message = 'Successfully updated %name.';
    }
    else {
      $message = 'Successfully added %name.';
    }
    drupal_set_message(t($message, [
      '%name' => $form_state
        ->getValues()['name'],
    ]));

    // Redirect back to Google Adwords Path admin page.
    $path = 'admin/config/system/google_adwords/path';
    $response = new RedirectResponse($path);
    $response
      ->send();
  }
  elseif ($form_state['clicked_button']['#value'] == 'Delete') {
    $path = 'admin/config/system/google_adwords/path/' . $form_state
      ->getValues()['cid'] . '/delete';
    $response = new RedirectResponse($path);
    $response
      ->send();
  }
}