You are here

public function GroupContentMenuForm::save in Group Content Menu 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/Form/GroupContentMenuForm.php, line 337

Class

GroupContentMenuForm
Form controller for Group menu instance edit forms.

Namespace

Drupal\group_content_menu\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $menu = $this
    ->getEntity();
  if (!$menu
    ->isNew()) {
    $this
      ->submitOverviewForm($form, $form_state);
  }
  $status = $menu
    ->save();
  $arguments = [
    '%label' => $this->entity
      ->label(),
  ];
  if ($status === SAVED_NEW) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('New group menu <em>%label</em> has been created.', $arguments));
    $this
      ->logger('group_content_menu')
      ->notice('Created new group menu %label', $arguments);
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The group menu <em>%label</em> has been update.', $arguments));
    $this
      ->logger('group_content_menu')
      ->notice('Updated group menu %label.', $arguments);
  }
}