You are here

public function MailgunHandler::validateMailgunApiSettings in Mailgun 8

Checks if API settings are correct and not empty.

Parameters

bool $showMessage: Whether error messages should be shown.

Return value

bool Whether API settings are valid.

Overrides MailgunHandlerInterface::validateMailgunApiSettings

2 calls to MailgunHandler::validateMailgunApiSettings()
MailgunHandler::moduleStatus in src/MailgunHandler.php
Validates Mailgun library and API settings.
MailgunHandler::sendMail in src/MailgunHandler.php
Connects to Mailgun API and sends out the email.

File

src/MailgunHandler.php, line 210

Class

MailgunHandler
Mail handler to send out an email message array to the Mailgun API.

Namespace

Drupal\mailgun

Code

public function validateMailgunApiSettings($showMessage = FALSE) {
  $apiKey = $this->mailgunConfig
    ->get('api_key');
  $workingDomain = $this->mailgunConfig
    ->get('working_domain');
  if (empty($apiKey) || empty($workingDomain)) {
    if ($showMessage) {
      $this->messenger
        ->addMessage("Please check your API settings. API key and domain shouldn't be empty.", 'warning');
    }
    return FALSE;
  }
  if (!$this
    ->validateMailgunApiKey($apiKey)) {
    if ($showMessage) {
      $this->messenger
        ->addMessage("Couldn't connect to the Mailgun API. Please check your API settings.", 'warning');
    }
    return FALSE;
  }
  return TRUE;
}