function ForumForm::save

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

Overrides TermForm::save

File

core/modules/forum/src/Form/ForumForm.php, line 75

Class

ForumForm
Base form for forum term edit forms.

Namespace

Drupal\forum\Form

Code

public function save(array $form, FormStateInterface $form_state) {
    $term = $this->entity;
    $term_storage = $this->entityTypeManager
        ->getStorage('taxonomy_term');
    $status = $term_storage->save($term);
    $route_name = $this->urlStub == 'container' ? 'entity.taxonomy_term.forum_edit_container_form' : 'entity.taxonomy_term.forum_edit_form';
    $route_parameters = [
        'taxonomy_term' => $term->id(),
    ];
    $link = Link::fromTextAndUrl($this->t('Edit'), new Url($route_name, $route_parameters))
        ->toString();
    $view_link = $term->toLink($term->getName())
        ->toString();
    switch ($status) {
        case SAVED_NEW:
            $this->messenger()
                ->addStatus($this->t('Created new @type %term.', [
                '%term' => $view_link,
                '@type' => $this->forumFormType,
            ]));
            $this->logger('forum')
                ->notice('Created new @type %term.', [
                '%term' => $term->getName(),
                '@type' => $this->forumFormType,
                'link' => $link,
            ]);
            $form_state->setValue('tid', $term->id());
            break;
        case SAVED_UPDATED:
            $this->messenger()
                ->addStatus($this->t('The @type %term has been updated.', [
                '%term' => $term->getName(),
                '@type' => $this->forumFormType,
            ]));
            $this->logger('forum')
                ->notice('Updated @type %term.', [
                '%term' => $term->getName(),
                '@type' => $this->forumFormType,
                'link' => $link,
            ]);
            break;
    }
    $form_state->setRedirect('forum.overview');
    return $term;
}

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