function MenuForm::save

Same name in other branches
  1. 9 core/modules/menu_ui/src/MenuForm.php \Drupal\menu_ui\MenuForm::save()
  2. 8.9.x core/modules/menu_ui/src/MenuForm.php \Drupal\menu_ui\MenuForm::save()
  3. 11.x core/modules/menu_ui/src/MenuForm.php \Drupal\menu_ui\MenuForm::save()

Overrides EntityForm::save

File

core/modules/menu_ui/src/MenuForm.php, line 179

Class

MenuForm
Base form for menu edit forms.

Namespace

Drupal\menu_ui

Code

public function save(array $form, FormStateInterface $form_state) {
    $menu = $this->entity;
    $status = $menu->save();
    $edit_link = $this->entity
        ->toLink($this->t('Edit'), 'edit-form')
        ->toString();
    if ($status == SAVED_UPDATED) {
        $this->messenger()
            ->addStatus($this->t('Menu %label has been updated.', [
            '%label' => $menu->label(),
        ]));
        $this->logger('menu')
            ->notice('Menu %label has been updated.', [
            '%label' => $menu->label(),
            'link' => $edit_link,
        ]);
    }
    else {
        $this->messenger()
            ->addStatus($this->t('Menu %label has been added.', [
            '%label' => $menu->label(),
        ]));
        $this->logger('menu')
            ->notice('Menu %label has been added.', [
            '%label' => $menu->label(),
            'link' => $edit_link,
        ]);
    }
    $form_state->setRedirectUrl($this->entity
        ->toUrl('edit-form'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.