function BookOutlineForm::save

Same name in other branches
  1. 9 core/modules/book/src/Form/BookOutlineForm.php \Drupal\book\Form\BookOutlineForm::save()
  2. 8.9.x core/modules/book/src/Form/BookOutlineForm.php \Drupal\book\Form\BookOutlineForm::save()
  3. 10 core/modules/book/src/Form/BookOutlineForm.php \Drupal\book\Form\BookOutlineForm::save()

Overrides EntityForm::save

File

core/modules/book/src/Form/BookOutlineForm.php, line 109

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', [
        'node' => $this->entity
            ->id(),
    ]);
    $book_link = $form_state->getValue('book');
    if (!$book_link['bid']) {
        $this->messenger()
            ->addStatus($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.
            $this->messenger()
                ->addStatus($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
                ->toUrl('book-outline-form'));
        }
        else {
            $this->messenger()
                ->addStatus($this->t('The book outline has been updated.'));
        }
    }
    else {
        $this->messenger()
            ->addError($this->t('There was an error adding the post to the book.'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.