You are here

public function MenuLinkContentForm::save in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/menu_link_content/src/Form/MenuLinkContentForm.php \Drupal\menu_link_content\Form\MenuLinkContentForm::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 EntityForm::save

File

core/modules/menu_link_content/src/Form/MenuLinkContentForm.php, line 127

Class

MenuLinkContentForm
Provides a form to add/update content menu links.

Namespace

Drupal\menu_link_content\Form

Code

public function save(array $form, FormStateInterface $form_state) {

  // The entity is rebuilt in parent::submit().
  $menu_link = $this->entity;
  $menu_link
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('The menu link has been saved.'));
  $form_state
    ->setRedirectUrl($menu_link
    ->toUrl('canonical'));
}