You are here

public function ForumForm::save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/forum/src/Form/ForumForm.php \Drupal\forum\Form\ForumForm::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 TermForm::save

File

core/modules/forum/src/Form/ForumForm.php, line 78
Contains \Drupal\forum\Form\ForumForm.

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->entityManager
    ->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 = $this
    ->l($this
    ->t('Edit'), new Url($route_name, $route_parameters));
  switch ($status) {
    case SAVED_NEW:
      drupal_set_message($this
        ->t('Created new @type %term.', array(
        '%term' => $term
          ->getName(),
        '@type' => $this->forumFormType,
      )));
      $this
        ->logger('forum')
        ->notice('Created new @type %term.', array(
        '%term' => $term
          ->getName(),
        '@type' => $this->forumFormType,
        'link' => $link,
      ));
      $form_state
        ->setValue('tid', $term
        ->id());
      break;
    case SAVED_UPDATED:
      drupal_set_message($this
        ->t('The @type %term has been updated.', array(
        '%term' => $term
          ->getName(),
        '@type' => $this->forumFormType,
      )));
      $this
        ->logger('forum')
        ->notice('Updated @type %term.', array(
        '%term' => $term
          ->getName(),
        '@type' => $this->forumFormType,
        'link' => $link,
      ));
      break;
  }
  $form_state
    ->setRedirect('forum.overview');
  return $term;
}