You are here

public function SettingsForm::settingsSubmitForm in Opigno Moxtra 8

Same name and namespace in other branches
  1. 3.x src/Form/SettingsForm.php \Drupal\opigno_moxtra\Form\SettingsForm::settingsSubmitForm()

File

src/Form/SettingsForm.php, line 253

Class

SettingsForm
Implements the Opigno Moxtra settings form.

Namespace

Drupal\opigno_moxtra\Form

Code

public function settingsSubmitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $config = \Drupal::configFactory()
    ->getEditable('opigno_moxtra.settings');
  $config
    ->setData([]);
  $config
    ->save();
  $connector = \Drupal::service('opigno_moxtra.connector');
  $token = $connector
    ->getToken(1, TRUE);
  $this
    ->config('opigno_moxtra.settings')
    ->set('url', $form_state
    ->getValue('moxtra_url'))
    ->set('client_id', $form_state
    ->getValue('client_id'))
    ->set('client_secret', $form_state
    ->getValue('client_secret'))
    ->set('email', $form_state
    ->getValue('moxtra_login'))
    ->set('org_id', $form_state
    ->getValue('org_id'))
    ->set('agreement', $form_state
    ->getValue('agreement'))
    ->set('status', !empty($token))
    ->save();
  $prefix = $this->keyValueStorage
    ->get('prefix');
  if (empty($prefix)) {
    $prefix = $this->request
      ->getCurrentRequest()
      ->getHost();
    $this->keyValueStorage
      ->set('prefix', $prefix);
  }
}