public function CustomLanguageForm::save in Custom Language field 8
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 EntityForm::save
File
- src/
Form/ CustomLanguageForm.php, line 69
Class
- CustomLanguageForm
- Form controller for the CustomLanguage entity edit forms.
Namespace
Drupal\languagefield\FormCode
public function save(array $form, FormStateInterface $form_state) {
$status = parent::save($form, $form_state);
/** @var \Drupal\languagefield\Entity\CustomLanguageInterface $entity */
$entity = $this->entity;
// $edit_link = $this->entity->toLink($this->t('Edit'),'edit-form');
$action = $status == SAVED_UPDATED ? 'updated' : 'added';
// Tell the user we've updated their custom language.
$this
->messenger()
->addStatus($this
->t('The language %label has been %action.', [
'%label' => $entity
->label(),
'%action' => $action,
]));
$this
->logger('languagefield')
->notice('The language %label has been %action.', [
'%label' => $entity
->label(),
'%action' => $action,
]);
// Redirect back to the list view.
$form_state
->setRedirect('languagefield.custom_language.collection');
}