You are here

public function WSFieldConfigForm::save in Web Service Data 2.0.x

Same name and namespace in other branches
  1. 8 modules/wsdata_field/src/Form/WSFieldConfigForm.php \Drupal\wsdata_field\Form\WSFieldConfigForm::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

modules/wsdata_field/src/Form/WSFieldConfigForm.php, line 143

Class

WSFieldConfigForm
Class WSFieldsConfigForm.

Namespace

Drupal\wsdata_field\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $wscall_entity = $this->entityTypeManager
    ->getStorage('wscall')
    ->load($form_state
    ->getValue('wscall'));
  $replacements = [];
  foreach ($wscall_entity
    ->getReplacements() as $replacement) {
    $replacements[$replacement] = $form_state
      ->getValue($replacement);
  }
  $wsfieldconfig_entity = $this->entity;
  $wsfieldconfig_entity->replacements = $replacements;
  $wsfieldconfig_entity->data = $form_state
    ->getValue('data');
  $wsfieldconfig_entity->languageHandling = $form_state
    ->getValue('languageHandling');
  $wsfieldconfig_entity
    ->save();

  // Set the redirect to the next destination in the steps.
  $request = $this
    ->getRequest();
  if (($destinations = $request->query
    ->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
    $request->query
      ->remove('destinations');
    $form_state
      ->setRedirectUrl($next_destination);
  }
  else {

    // If no redirect is set go to the entity type and bundle field UI page.
    $field_config = $form_state
      ->get('field_config');
    $form_state
      ->setRedirectUrl(FieldUI::getOverviewRouteInfo($field_config
      ->getTargetEntityTypeId(), $field_config
      ->getTargetBundle()));
  }
}