You are here

public function AuthorPaneFormBase::save in Author Pane 8.3

Overrides Drupal\Core\Entity\EntityFormController::save().

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.

Overrides EntityForm::save

File

src/Form/AuthorPaneFormBase.php, line 172
Contains \Drupal\author_pane\Form\AuthorPaneFormBase.

Class

AuthorPaneFormBase
Class AuthorPaneFormBase.

Namespace

Drupal\author_pane\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $authorPane = $this
    ->getEntity();
  $status = $authorPane
    ->save();

  // Grab the URL of the new entity. We'll use it in the message.
  $url = $authorPane
    ->urlInfo();

  // Create an edit link.
  $edit_link = $this
    ->l($this
    ->t('Edit'), $url);
  if ($status == SAVED_UPDATED) {

    // If we edited an existing entity...
    drupal_set_message($this
      ->t('AuthorPane %label has been updated.', array(
      '%label' => $authorPane
        ->label(),
    )));
    $this
      ->logger('contact')
      ->notice('AuthorPane %label has been updated.', [
      '%label' => $authorPane
        ->label(),
      'link' => $edit_link,
    ]);
  }
  else {

    // If we created a new entity...
    drupal_set_message($this
      ->t('AuthorPane %label has been added.', array(
      '%label' => $authorPane
        ->label(),
    )));
    $this
      ->logger('contact')
      ->notice('AuthorPane %label has been added.', [
      '%label' => $authorPane
        ->label(),
      'link' => $edit_link,
    ]);
  }

  // Redirect the user back to the listing route after the save operation.
  $form_state
    ->setRedirect('entity.author_pane.list');
}