You are here

public function ConfigurationSendinblueForm::submitForm in SendinBlue 8

Same name and namespace in other branches
  1. 8.2 src/Form/ConfigurationSendinblueForm.php \Drupal\sendinblue\Form\ConfigurationSendinblueForm::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/ConfigurationSendinblueForm.php, line 139

Class

ConfigurationSendinblueForm
Parameter Form to login SendinBlue.

Namespace

Drupal\sendinblue\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $accessKey = $form_state
    ->getValue('access_key');
  $config = $this->configFactory
    ->getEditable(SendinblueManager::CONFIG_SETTINGS);
  $configRegistering = $this
    ->configFactory()
    ->getEditable(SendinblueManager::CONFIG_SETTINGS_REGISTERING_USER);
  $sendinblueMailin = $this->sendinblueManager
    ->updateSendinblueMailin($accessKey);
  $sibAccount = $sendinblueMailin
    ->getAccount();
  if (isset($sibAccount)) {
    $account_user_name = $sibAccount
      ->getFirstName() . ' ' . $sibAccount
      ->getLastName();
    $config
      ->set(SendinblueManager::ACCESS_KEY, $accessKey)
      ->save();
    $config
      ->set(SendinblueManager::ACCOUNT_EMAIL, $sibAccount
      ->getEmail())
      ->save();
    $config
      ->set(SendinblueManager::ACCOUNT_USERNAME, $account_user_name)
      ->save();
    $config
      ->set(SendinblueManager::ACCOUNT_DATA, Json::encode($sibAccount))
      ->save();
    $configRegistering
      ->set('sendinblue_put_registered_user', '0')
      ->save();
    $this->sendinblueManager
      ->updateSmtpDetails();
    $sendinblueMailin
      ->partnerDrupal();
  }

  // Clear cache for menu tasks.
  $this->cacheBackend
    ->invalidateAll();
  $this->menuLinkManager
    ->rebuild();
  parent::submitForm($form, $form_state);
}