You are here

public function MegaMenuAdd::save in The Better Mega Menu 8

Same name and namespace in other branches
  1. 2.x src/Form/MegaMenuAdd.php \Drupal\tb_megamenu\Form\MegaMenuAdd::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

src/Form/MegaMenuAdd.php, line 138

Class

MegaMenuAdd
Form handler for adding MegaMenuConfig entities.

Namespace

Drupal\tb_megamenu\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $megamenu = $this->entity;
  $status = $megamenu
    ->save();
  if ($status) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Created the %label Mega Menu, edit it to configure.', [
      '%label' => $megamenu->menu,
    ]));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The %label Example was not saved.', [
      '%label' => $megamenu->menu,
    ]));
  }
  $form_state
    ->setRedirect('entity.tb_megamenu.edit_form', [
    'tb_megamenu' => $megamenu
      ->id(),
  ]);
}