ForumForm::save

public ForumForm::save(array $form, FormStateInterface $form_state)

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 73

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));
  $view_link = $term->link($term->getName());
  switch ($status) {
    case SAVED_NEW:
      drupal_set_message($this->t('Created new @type %term.', array('%term' => $view_link, '@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;
}
doc_Drupal
2016-10-29 09:17:07
Comments
Leave a Comment

Please login to continue.