You are here

public function BookOutlineForm::save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/Form/BookOutlineForm.php \Drupal\book\Form\BookOutlineForm::save()

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/book/src/Form/BookOutlineForm.php, line 102
Contains \Drupal\book\Form\BookOutlineForm.

Class

BookOutlineForm
Displays the book outline form.

Namespace

Drupal\book\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $form_state
    ->setRedirect('entity.node.canonical', array(
    'node' => $this->entity
      ->id(),
  ));
  $book_link = $form_state
    ->getValue('book');
  if (!$book_link['bid']) {
    drupal_set_message($this
      ->t('No changes were made'));
    return;
  }
  $this->entity->book = $book_link;
  if ($this->bookManager
    ->updateOutline($this->entity)) {
    if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {

      // This will usually only happen when JS is disabled.
      drupal_set_message($this
        ->t('The post has been added to the selected book. You may now position it relative to other pages.'));
      $form_state
        ->setRedirectUrl($this->entity
        ->urlInfo('book-outline-form'));
    }
    else {
      drupal_set_message($this
        ->t('The book outline has been updated.'));
    }
  }
  else {
    drupal_set_message($this
      ->t('There was an error adding the post to the book.'), 'error');
  }
}