You are here

public function WSServerForm::save in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x src/Form/WSServerForm.php \Drupal\wsdata\Form\WSServerForm::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/WSServerForm.php, line 113

Class

WSServerForm
Class WSServerForm.

Namespace

Drupal\wsdata\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $wsserver_entity = $this->entity;
  $status = $wsserver_entity
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Created the %label Web Service Server.', [
        '%label' => $wsserver_entity
          ->label(),
      ]));
      break;
    default:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Saved the %label Web Service Server.', [
        '%label' => $wsserver_entity
          ->label(),
      ]));
  }

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // Please confirm that `$wsserver_entity` is an instance of `Drupal\Core\Entity\EntityInterface`. Only the method name and not the class name was checked for this replacement, so this may be a false positive.
  $form_state
    ->setRedirectUrl($wsserver_entity
    ->toUrl('collection'));
}