You are here

public function MenuForm::save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/src/MenuForm.php \Drupal\menu_ui\MenuForm::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_ui/src/MenuForm.php, line 179
Contains \Drupal\menu_ui\MenuForm.

Class

MenuForm
Base form for menu edit forms.

Namespace

Drupal\menu_ui

Code

public function save(array $form, FormStateInterface $form_state) {
  $menu = $this->entity;
  if (!$menu
    ->isNew() || $menu
    ->isLocked()) {
    $this
      ->submitOverviewForm($form, $form_state);
  }
  $status = $menu
    ->save();
  $edit_link = $this->entity
    ->link($this
    ->t('Edit'));
  if ($status == SAVED_UPDATED) {
    drupal_set_message($this
      ->t('Menu %label has been updated.', array(
      '%label' => $menu
        ->label(),
    )));
    $this
      ->logger('menu')
      ->notice('Menu %label has been updated.', array(
      '%label' => $menu
        ->label(),
      'link' => $edit_link,
    ));
  }
  else {
    drupal_set_message($this
      ->t('Menu %label has been added.', array(
      '%label' => $menu
        ->label(),
    )));
    $this
      ->logger('menu')
      ->notice('Menu %label has been added.', array(
      '%label' => $menu
        ->label(),
      'link' => $edit_link,
    ));
  }
  $form_state
    ->setRedirectUrl($this->entity
    ->urlInfo('edit-form'));
}