function TermForm::save
Same name in other branches
- 9 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::save()
- 8.9.x core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::save()
- 10 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::save()
Overrides EntityForm::save
1 method overrides TermForm::save()
- ForumForm::save in core/
modules/ forum/ src/ Form/ ForumForm.php - Form submission handler for the 'save' action.
File
-
core/
modules/ taxonomy/ src/ TermForm.php, line 194
Class
- TermForm
- Base for handler for taxonomy term edit forms.
Namespace
Drupal\taxonomyCode
public function save(array $form, FormStateInterface $form_state) {
$term = $this->entity;
$result = $term->save();
$edit_link = $term->toLink($this->t('Edit'), 'edit-form')
->toString();
$view_link = $term->toLink()
->toString();
switch ($result) {
case SAVED_NEW:
$this->messenger()
->addStatus($this->t('Created new term %term.', [
'%term' => $view_link,
]));
$this->logger('taxonomy')
->info('Created new term %term.', [
'%term' => $term->getName(),
'link' => $edit_link,
]);
break;
case SAVED_UPDATED:
$this->messenger()
->addStatus($this->t('Updated term %term.', [
'%term' => $view_link,
]));
$this->logger('taxonomy')
->info('Updated term %term.', [
'%term' => $term->getName(),
'link' => $edit_link,
]);
// Redirect to term view page if user has access, otherwise the form
// will be displayed again.
$canonicalUrl = $term->toUrl();
if ($canonicalUrl->access()) {
$form_state->setRedirectUrl($canonicalUrl);
}
break;
}
$current_parent_count = count($form_state->getValue('parent'));
// Root doesn't count if it's the only parent.
if ($current_parent_count == 1 && $form_state->hasValue([
'parent',
0,
])) {
$form_state->setValue('parent', []);
}
$form_state->setValue('tid', $term->id());
$form_state->set('tid', $term->id());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.