public function Api::__construct in SendGrid Integration 8.2
Same name and namespace in other branches
- 8 modules/sendgrid_integration_reports/src/Api.php \Drupal\sendgrid_integration_reports\Api::__construct()
Api constructor.
Parameters
\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The configuration factory.
\Drupal\Core\Messenger\MessengerInterface $messenger: The messenger service.
\Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory: The logger factory.
\Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler: The module handler service.
\Drupal\Core\Cache\CacheFactoryInterface $cacheFactory: The cache factory service.
File
- modules/
sendgrid_integration_reports/ src/ Api.php, line 84
Class
- Api
- Class SendGridReportsController.
Namespace
Drupal\sendgrid_integration_reportsCode
public function __construct(ConfigFactoryInterface $config_factory, MessengerInterface $messenger, LoggerChannelFactoryInterface $logger_factory, ModuleHandlerInterface $moduleHandler, CacheFactoryInterface $cacheFactory) {
$this->configFactory = $config_factory;
$this->messenger = $messenger;
$this->loggerFactory = $logger_factory;
$this->moduleHandler = $moduleHandler;
$this->cacheFactory = $cacheFactory;
// Load key from variables and throw errors if not there.
$key_secret = $this->configFactory
->get('sendgrid_integration.settings')
->get('apikey');
if ($this->moduleHandler
->moduleExists('key')) {
$key = \Drupal::service('key.repository')
->getKey($key_secret);
if ($key && $key
->getKeyValue()) {
$this->apiKey = $key
->getKeyValue();
}
}
else {
$this->apiKey = $key_secret;
}
// Display message one time if api key is not set.
if (empty($this->apiKey)) {
$this->loggerFactory
->get('sendgrid_integration_reports')
->warning(t('SendGrid Module is not setup with API key.'));
$this->messenger
->addWarning('Sendgrid Module is not setup with an API key.');
}
}