You are here

public function RestUIForm::submitForm in REST UI 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/RestUIForm.php, line 418

Class

RestUIForm
Provides a REST resource configuration form.

Namespace

Drupal\restui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $resource_id = str_replace(':', '.', $form_state
    ->getValue('resource_id'));
  $config = $this->resourceConfigStorage
    ->load($resource_id);
  $granularity = $form_state
    ->getValue('granularity');
  if (!$config) {
    $config = $this->resourceConfigStorage
      ->create([
      'id' => $resource_id,
    ]);
  }
  $configuration = $granularity === RestResourceConfigInterface::RESOURCE_GRANULARITY ? static::getConfigurationForResourceGranularity($form_state) : static::getConfigurationForMethodGranularity($form_state);
  $config
    ->set('granularity', $granularity);
  $config
    ->set('configuration', $configuration);
  $config
    ->enable();
  $config
    ->save();
  $this->messenger
    ->addStatus($this
    ->t('The resource has been updated.'));

  // Redirect back to the listing.
  $form_state
    ->setRedirect('restui.list');
}