ContactFormEditForm::save

public ContactFormEditForm::save(array $form, FormStateInterface $form_state)

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

core/modules/contact/src/ContactFormEditForm.php, line 160

Class

ContactFormEditForm
Base form for contact form edit forms.

Namespace

Drupal\contact

Code

public function save(array $form, FormStateInterface $form_state) {
  $contact_form = $this->entity;
  $status = $contact_form->save();
  $contact_settings = $this->config('contact.settings');

  $edit_link = $this->entity->link($this->t('Edit'));
  $view_link = $contact_form->link($contact_form->label(), 'canonical');
  if ($status == SAVED_UPDATED) {
    drupal_set_message($this->t('Contact form %label has been updated.', array('%label' => $view_link)));
    $this->logger('contact')->notice('Contact form %label has been updated.', array('%label' => $contact_form->label(), 'link' => $edit_link));
  }
  else {
    drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $view_link)));
    $this->logger('contact')->notice('Contact form %label has been added.', array('%label' => $contact_form->label(), 'link' => $edit_link));
  }

  // Update the default form.
  if ($form_state->getValue('selected')) {
    $contact_settings
    ->set('default_form', $contact_form->id())
      ->save();
  }
  // If it was the default form, empty out the setting.
  elseif ($contact_settings->get('default_form') == $contact_form->id()) {
    $contact_settings
    ->set('default_form', NULL)
      ->save();
  }

  $form_state->setRedirectUrl($contact_form->urlInfo('collection'));
}
doc_Drupal
2016-10-29 08:56:26
Comments
Leave a Comment

Please login to continue.