You are here

public function BynderConfigurationForm::submitForm in Bynder 8

Same name and namespace in other branches
  1. 8.3 src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::submitForm()
  2. 8.2 src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::submitForm()
  3. 4.0.x src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::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/BynderConfigurationForm.php, line 401

Class

BynderConfigurationForm
Configure bynder to enable OAuth based access.

Namespace

Drupal\bynder\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $is_initial_save = $this
    ->config('bynder.settings')
    ->get('consumer_key') === '';
  $is_initial_save &= $this
    ->config('bynder.settings')
    ->get('consumer_secret') === '';
  $is_initial_save &= $this
    ->config('bynder.settings')
    ->get('token') === '';
  $is_initial_save &= $this
    ->config('bynder.settings')
    ->get('token_secret') === '';
  $account_domain = $this
    ->config('bynder.settings')
    ->get('account_domain');
  $is_initial_save &= $account_domain === '';
  $credentials = $form_state
    ->getValue('credentials');
  $restrictions = $form_state
    ->getValue('restrictions');
  $this
    ->config('bynder.settings')
    ->set('consumer_key', $credentials['consumer_key'])
    ->set('consumer_secret', $credentials['consumer_secret'])
    ->set('token', $credentials['token'])
    ->set('token_secret', $credentials['token_secret'])
    ->set('account_domain', $credentials['account_domain'])
    ->set('debug', $form_state
    ->getValue('debug'))
    ->set('cache_lifetime', $form_state
    ->getValue('cache_lifetime'))
    ->set('timeout', $form_state
    ->getValue('timeout'))
    ->set('usage_metaproperty', $form_state
    ->getValue('usage_metaproperty'))
    ->set('restrictions.royalty_free', $restrictions['royalty_free'])
    ->set('restrictions.web_license', $restrictions['web_license'])
    ->set('restrictions.print_license', $restrictions['print_license'])
    ->save();
  parent::submitForm($form, $form_state);

  // If this is the first time we're configuring credentials also update
  // cached data.
  if ($is_initial_save || $account_domain !== $form_state
    ->getValue('account_domain')) {
    try {
      $this->bynder
        ->updateCachedData();
    } catch (\Exception $exception) {
    }
  }
}