You are here

public function FormAssemblyEntitySettingsForm::submitForm in FormAssembly 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 FormInterface::submitForm

File

src/Form/FormAssemblyEntitySettingsForm.php, line 96

Class

FormAssemblyEntitySettingsForm
FormAssembly entity settings form.

Namespace

Drupal\formassembly\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Config\Config $formassembly_config */
  $values = $form_state
    ->getValues();
  $config = [
    'endpoint' => $values['endpoint'],
    'admin_index' => $values['admin_index'],
    'credentials' => [
      'provider' => $values['provider'],
    ],
  ];
  switch ($values['provider']) {
    case 'formassembly':
      $config['credentials']['data']['cid'] = $values['cid'];
      $config['credentials']['data']['secret'] = $values['secret'];
      break;
    case 'key':
      $config['credentials']['data']['id'] = $values['id'];
      break;
  }
  $this->formassemblyConfig
    ->setData($config)
    ->save();
  $sync = $form_state
    ->getValue('batch_sync');
  $reauthorize = $form_state
    ->getValue('reauthorize');
  if ($reauthorize || !$this->authorize
    ->isAuthorized()) {
    $form_state
      ->setRedirect('fa_form.authorize');
  }
  if ($sync) {

    // Setup a batch.
    $batch = [
      'operations' => [
        [
          'formassembly_batch_get_forms',
          [],
        ],
      ],
      'finished' => 'formassembly_batch_finished',
      'title' => 'Request Forms Data from FormAssembly',
      'init_message' => 'Contacting FormAssembly',
    ];
    batch_set($batch);
  }
}