MenuLinkContentForm::save

public MenuLinkContentForm::save(array $form, FormStateInterface $form_state)

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 117

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;
  $saved = $menu_link->save();

  if ($saved) {
    drupal_set_message($this->t('The menu link has been saved.'));
    $form_state->setRedirect(
    'entity.menu_link_content.canonical', 
    array('menu_link_content' => $menu_link->id())
    );
  }
  else {
    drupal_set_message($this->t('There was an error saving the menu link.'), 'error');
    $form_state->setRebuild();
  }
}
doc_Drupal
2016-10-29 09:26:44
Comments
Leave a Comment

Please login to continue.