You are here

public function DomainAliasForm::save in Domain Access 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

domain_alias/src/DomainAliasForm.php, line 218

Class

DomainAliasForm
Base form controller for domain alias edit forms.

Namespace

Drupal\domain_alias

Code

public function save(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\domain_alias\DomainAliasInterface $alias */
  $alias = $this->entity;
  $edit_link = $alias
    ->toLink($this
    ->t('Edit'), 'edit-form')
    ->toString();
  if ($alias
    ->save() == SAVED_NEW) {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Created new domain alias.'));
    $this
      ->logger('domain_alias')
      ->notice('Created new domain alias %name.', [
      '%name' => $alias
        ->label(),
      'link' => $edit_link,
    ]);
  }
  else {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Updated domain alias.'));
    $this
      ->logger('domain_alias')
      ->notice('Updated domain alias %name.', [
      '%name' => $alias
        ->label(),
      'link' => $edit_link,
    ]);
  }
  $form_state
    ->setRedirect('domain_alias.admin', [
    'domain' => $alias
      ->getDomainId(),
  ]);
}