You are here

public function JsonapiResourceConfigForm::save in JSON:API Extras 8.3

Same name and namespace in other branches
  1. 8 src/Form/JsonapiResourceConfigForm.php \Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm::save()
  2. 8.2 src/Form/JsonapiResourceConfigForm.php \Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm::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/JsonapiResourceConfigForm.php, line 203

Class

JsonapiResourceConfigForm
Base form for jsonapi_resource_config.

Namespace

Drupal\jsonapi_extras\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $resource_config = $this->entity;
  $status = $resource_config
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Created the %label JSON:API Resource overwrites.', [
        '%label' => $resource_config
          ->label(),
      ]));
      break;
    default:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Saved the %label JSON:API Resource overwrites.', [
        '%label' => $resource_config
          ->label(),
      ]));
  }
  $form_state
    ->setRedirectUrl($resource_config
    ->toUrl('collection'));
}