You are here

public function GoogleAdwordsPathConfigForm::save in Google AdWords Conversion Tracking 8

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityForm::save

File

modules/google_adwords_path/src/Form/GoogleAdwordsPathConfigForm.php, line 117
Contains Drupal\google_adwords_path\Form\GoogleAdwordsPathConfigForm.

Class

GoogleAdwordsPathConfigForm
Class GoogleAdwordsPathConfigForm.

Namespace

Drupal\google_adwords_path\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $path_config = $this->entity;
  $status = $path_config
    ->save();
  switch ($status) {
    case SAVED_NEW:
      drupal_set_message($this
        ->t('Created the %label Google AdWords Path Config.', [
        '%label' => $path_config
          ->label(),
      ]));
      break;
    default:
      drupal_set_message($this
        ->t('Saved the %label Google AdWords Path Config.', [
        '%label' => $path_config
          ->label(),
      ]));
  }
  $form_state
    ->setRedirectUrl($path_config
    ->urlInfo('collection'));

  /**
   * @var \Drupal\google_adwords_path\GoogleAdwordsPathTracker $pathTracker
   *  The path tracker service, which will be used to invalidate the cache
   */
  $pathTracker = \DRUPAL::service('google_adwords_path.pathtracker');

  // re-build the tree
  if ($pathTracker instanceof GoogleAdwordsPathTracker) {
    $pathTracker
      ->buildPathTree(TRUE);
  }
  else {
    drupal_set_message(__METHOD__ . '::' . __LINE__ . ':: CACHE CLEAR FAIL');
  }
}