You are here

public function WebformEntitySettingsGeneralForm::save in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/EntitySettings/WebformEntitySettingsGeneralForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsGeneralForm::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 WebformEntitySettingsBaseForm::save

File

src/EntitySettings/WebformEntitySettingsGeneralForm.php, line 535

Class

WebformEntitySettingsGeneralForm
Webform general settings.

Namespace

Drupal\webform\EntitySettings

Code

public function save(array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $this
    ->getEntity();

  // Set third party settings.
  if (isset($values['third_party_settings'])) {
    $third_party_settings = $values['third_party_settings'];
    foreach ($third_party_settings as $module => $third_party_setting) {
      if (empty($third_party_setting)) {
        $webform
          ->unsetThirdPartySettings($module);
      }
      else {
        foreach ($third_party_setting as $key => $value) {
          $webform
            ->setThirdPartySetting($module, $key, $value);
        }
      }
    }

    // Remove third party settings.
    unset($values['third_party_settings']);
  }

  // Remove main properties.
  unset($values['id'], $values['title'], $values['description'], $values['category'], $values['weight'], $values['template'], $values['uid']);

  // Set settings.
  $webform
    ->setSettings($values);
  parent::save($form, $form_state);
}