You are here

public function MenuLinkConfigForm::save in Config menu link 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/Plugin/Menu/Form/MenuLinkConfigForm.php, line 327
Contains \Drupal\menu_link_config\Plugin\Menu\Form\MenuLinkConfigForm.

Class

MenuLinkConfigForm

Namespace

Drupal\menu_link_config\Plugin\Menu\Form

Code

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

  // The entity is rebuilt in parent::submit().
  $menu_link = $this->entity;
  $saved = $menu_link
    ->save();
  if ($saved) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The menu link has been saved.'));
    $form_state
      ->setRedirect('entity.menu.edit_form', array(
      'menu' => $menu_link
        ->getMenuName(),
    ));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('There was an error saving the menu link.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
}