You are here

public function SendinblueManager::updateSmtpDetails in SendinBlue 8

Same name and namespace in other branches
  1. 8.2 src/SendinblueManager.php \Drupal\sendinblue\SendinblueManager::updateSmtpDetails()

Update smtp details.

Return value

string|bool A access token if exist, else 0.

File

src/SendinblueManager.php, line 672

Class

SendinblueManager
Basic manager of module.

Namespace

Drupal\sendinblue

Code

public function updateSmtpDetails() {
  $smtpDetails = $this->sendinblueMailin
    ->getSmtpDetails();
  $config = $this->configFactory
    ->getEditable(self::CONFIG_SETTINGS_SEND_EMAIL);
  $drupalEmailconfig = $this->configFactory
    ->getEditable('system.mail');
  if (isset($smtpDetails) && $smtpDetails
    ->isEnabled()) {

    // Set SendinBlue SMTP on ON.
    $config
      ->set('sendinblue_on', 1)
      ->save();
    $config
      ->set(self::SMTP_DETAILS, Json::encode($smtpDetails))
      ->save();

    // Set DRUPAL SMTP on ON with SiB.
    $drupalEmailconfig
      ->set('interface.default', 'sendinblue_mail')
      ->save();
    return $smtpDetails;
  }

  // Set SendinBlue SMTP on OFF.
  $config
    ->set('sendinblue_on', 0)
    ->save();
  $config
    ->set(self::SMTP_DETAILS, NULL)
    ->save();

  // Set DRUPAL SMTP on OFF with SiB, reset with php_mail.
  $drupalEmailconfig
    ->set('interface.default', 'php_mail')
    ->save();
  return NULL;
}