You are here

public function DisqusSettingsForm::submitForm in Disqus 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 ConfigFormBase::submitForm

File

src/Form/DisqusSettingsForm.php, line 266

Class

DisqusSettingsForm
Provides Disqus settings form.

Namespace

Drupal\disqus\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('disqus.settings');
  $config
    ->set('disqus_domain', $form_state
    ->getValue('disqus_domain'))
    ->set('behavior.disqus_localization', $form_state
    ->getValue('disqus_localization'))
    ->set('behavior.disqus_inherit_login', $form_state
    ->getValue('disqus_inherit_login'))
    ->set('behavior.disqus_track_newcomment_ga', $form_state
    ->getValue('disqus_track_newcomment_ga'))
    ->set('advanced.disqus_useraccesstoken', $form_state
    ->getValue('disqus_useraccesstoken'))
    ->set('advanced.disqus_publickey', $form_state
    ->getValue('disqus_publickey'))
    ->set('advanced.disqus_secretkey', $form_state
    ->getValue('disqus_secretkey'))
    ->set('advanced.sso.disqus_sso', $form_state
    ->getValue('disqus_sso'))
    ->set('advanced.sso.disqus_use_site_logo', $form_state
    ->getValue('disqus_use_site_logo'))
    ->save();
  if ($form_state
    ->hasValue('disqus_api_update')) {
    $config
      ->set('advanced.api.disqus_api_update', $form_state
      ->getValue('disqus_api_update'))
      ->save();
  }
  if ($form_state
    ->hasValue('disqus_api_delete')) {
    $config
      ->set('advanced.api.disqus_api_delete', $form_state
      ->getValue('disqus_api_delete'))
      ->save();
  }
  $old_logo = $config
    ->get('advanced.sso.disqus_logo');
  $new_logo = !$form_state
    ->isValueEmpty('disqus_logo') ? $form_state
    ->getValue([
    'disqus_logo',
    0,
  ]) : '';

  // Ignore if the file hasn't changed.
  if ($new_logo != $old_logo) {

    // Remove the old file and usage if previously set.
    if (!empty($old_logo)) {
      $file = $this->entityTypeManager
        ->getStorage('file')
        ->load($old_logo);
      $this->fileUsage
        ->delete($file, 'disqus', 'disqus');
    }

    // Update the new file and usage.
    if (!empty($new_logo)) {
      $file = $this->entityTypeManager
        ->getStorage('file')
        ->load($new_logo);
      $this->fileUsage
        ->add($file, 'disqus', 'disqus', 1);
    }
  }
  $config
    ->set('advanced.sso.disqus_logo', $new_logo)
    ->save();
  parent::submitForm($form, $form_state);
}