You are here

public function LegalAdminTermsForm::submitForm in Legal 8

Same name and namespace in other branches
  1. 2.0.x src/Form/LegalAdminTermsForm.php \Drupal\legal\Form\LegalAdminTermsForm::submitForm()

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/LegalAdminTermsForm.php, line 372

Class

LegalAdminTermsForm
Settings form for administering content of Terms & Conditions.

Namespace

Drupal\legal\Form

Code

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

  // Preview request, don't save anything.
  if ($form_state
    ->getTriggeringElement()['#value'] == $this
    ->t('Preview')) {
    return;
  }
  $this->configFactory
    ->getEditable('legal.settings')
    ->set('registration_terms_style', $values['registration_terms_style'])
    ->set('registration_container', $values['registration_container'])
    ->set('registration_modal_terms', $values['registration_modal_terms'])
    ->set('login_terms_style', $values['login_terms_style'])
    ->set('login_container', $values['login_container'])
    ->set('login_modal_terms', $values['login_modal_terms'])
    ->save();

  // If new conditions are different from current, enter in database.
  if ($this
    ->legalConditionsUpdated($values)) {
    $version = legal_version($values['version_handling'], $values['language']);
    Conditions::create([
      'version' => $version['version'],
      'revision' => $version['revision'],
      'language' => $values['language'],
      'conditions' => $values['conditions']['value'],
      'format' => $values['conditions']['format'],
      'date' => time(),
      'extras' => serialize($values['extras']),
      'changes' => $values['changes'],
    ])
      ->save();
    $this
      ->messenger()
      ->addMessage(t('Terms & Conditions have been saved.'));
  }
  parent::submitForm($form, $form_state);

  // @todo flush only the cache elements that need to be flushed.
  drupal_flush_all_caches();
}