You are here

public function WSCallForm::save in Web Service Data 8

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

Class

WSCallForm
Class WSCallForm.

Namespace

Drupal\wsdata\Form

Code

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

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // Please confirm that `$wscall_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($wscall_entity
    ->toUrl('collection'));
}