Skip to content
Snippets Groups Projects
Commit b22c78bf authored by davisben's avatar davisben
Browse files

Issue #3316452: Call to a member function getClientArgs() on bool in...

Issue #3316452: Call to a member function getClientArgs() on bool in Drupal\aws\AwsClientFactory->getClient()
parent 571f6252
No related branches found
No related tags found
1 merge request!9Issue #3316452: Call to a member function getClientArgs() on bool in Drupal\aws\AwsClientFactory->getClient()
...@@ -77,6 +77,13 @@ class AmazonSesHandler implements AmazonSesHandlerInterface { ...@@ -77,6 +77,13 @@ class AmazonSesHandler implements AmazonSesHandlerInterface {
$this->config = $config_factory->get('amazon_ses.settings'); $this->config = $config_factory->get('amazon_ses.settings');
} }
/**
* {@inheritdoc}
*/
public function getClient() {
return $this->client;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -9,6 +9,14 @@ use Symfony\Component\Mime\Email; ...@@ -9,6 +9,14 @@ use Symfony\Component\Mime\Email;
*/ */
interface AmazonSesHandlerInterface { interface AmazonSesHandlerInterface {
/**
* Get the AWS SES client.
*
* @return \Aws\SesV2\SesV2Client
* The AWS SES client.
*/
public function getClient();
/** /**
* Send an email using the AWS SDK. * Send an email using the AWS SDK.
* *
......
...@@ -29,6 +29,10 @@ class AmazonSesController extends ControllerBase { ...@@ -29,6 +29,10 @@ class AmazonSesController extends ControllerBase {
* A render array to build the page. * A render array to build the page.
*/ */
public function statistics() { public function statistics() {
if (!$this->verifyClient()) {
return [];
}
$quota = $this->handler->getSendQuota(); $quota = $this->handler->getSendQuota();
return [ return [
......
...@@ -33,29 +33,32 @@ class AmazonSesIdentitiesForm extends AmazonSesFormBase { ...@@ -33,29 +33,32 @@ class AmazonSesIdentitiesForm extends AmazonSesFormBase {
'status' => $this->t('Status'), 'status' => $this->t('Status'),
]; ];
$identities = $this->handler->getIdentities();
$options = []; $options = [];
foreach ($identities as $identity) { if ($this->verifyClient()) {
$options[$identity['identity']] = [ $identities = $this->handler->getIdentities();
'identity' => $identity['identity'],
'type' => $identity['type'], foreach ($identities as $identity) {
'status' => $identity['status'], $options[$identity['identity']] = [
]; 'identity' => $identity['identity'],
'type' => $identity['type'],
if ($identity['type'] == 'Domain') { 'status' => $identity['status'],
$record = "<strong>Name:</strong> _amazonses.{$identity['identity']}<br/>
<strong>Type:</strong> TXT<br/>
<strong>Value:</strong> {$identity['token']}";
$options[$identity['identity']]['record'] = [
'data' => [
'#markup' => $record,
],
]; ];
}
else { if ($identity['type'] == 'Domain') {
$options[$identity['identity']]['record'] = ''; $record = "<strong>Name:</strong> _amazonses.{$identity['identity']}<br/>
<strong>Type:</strong> TXT<br/>
<strong>Value:</strong> {$identity['token']}";
$options[$identity['identity']]['record'] = [
'data' => [
'#markup' => $record,
],
];
}
else {
$options[$identity['identity']]['record'] = '';
}
} }
} }
......
...@@ -30,4 +30,21 @@ trait HandlerTrait { ...@@ -30,4 +30,21 @@ trait HandlerTrait {
return $this; return $this;
} }
/**
* Verify that the AWS SES client has been initialized.
*
* @return bool
* TRUE if the client is initialized, FALSE if not.
*/
protected function verifyClient() {
$client = $this->handler->getClient();
if (!$client) {
$this->messenger()->addError($this->t('Unable to initialize the SES
client. More information may be available in the log.'));
}
return (bool) $client;
}
} }
<?php
namespace Drupal\Tests\amazon_ses\Functional;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Response;
/**
* Tests functionality when the AWS SES client is missing.
*
* @group amazon_ses
*/
class MissingClientTest extends FunctionalTestBase {
/**
* Tests the error message is shown when the client can't be initialized.
*/
public function testErrorMessage() {
$this->drupalGet(Url::fromRoute('amazon_ses.identities'));
$this->assertSession()->pageTextContains('Unable to initialize the SES client.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment