Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds_sendgrid / dds_sendgrid.install
Size: Mime:
<?php

use Drupal\Core\Url;
use Drupal\mailsystem\MailsystemManager;

/**
 * Implements hook_install().
 */
function dds_sendgrid_install() {
  $mailsystem_config = \Drupal::configFactory()->getEditable('mailsystem.settings');
  $prefix = MailsystemManager::MAILSYSTEM_MODULES_CONFIG . '.dds_sendgrid.none';
  $mailsystem_config->set($prefix . '.' . MailsystemManager::MAILSYSTEM_TYPE_FORMATTING, 'sendgrid');
  $mailsystem_config->set($prefix . '.' . MailsystemManager::MAILSYSTEM_TYPE_SENDING, 'sendgrid');
  $mailsystem_config->save();
}

/**
 * Implements hook_uninstall().
 */
function dds_sendgrid_uninstall() {
  $mailsystem_config = \Drupal::configFactory()->getEditable('mailsystem.settings');
  $prefix = MailsystemManager::MAILSYSTEM_MODULES_CONFIG . '.dds_sendgrid.none';
  $mailsystem_config->clear($prefix . '.' . MailsystemManager::MAILSYSTEM_TYPE_FORMATTING);
  $mailsystem_config->clear($prefix . '.' . MailsystemManager::MAILSYSTEM_TYPE_SENDING);
  $mailsystem_config->save();
}

/**
 * Implements hook_requirements().
 */
function dds_sendgrid_requirements($phase) {
  $requirements = [];
  $config = \Drupal::configFactory()->get('dds_sendgrid.settings');
  switch ($phase) {
    case 'runtime':
      if (empty($config->get('api_key'))) {
        $requirements['dds_sendgrid_api'] = [
          'title' => t('SendGrid API Key'),
          'value' => t('API Key Not Set'),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('You need to <a href="@url">add a SendGrid API Secret Key</a> for Drupal to be able to deliver mail through SendGrid.', [
            '@url' => Url::fromRoute('sendgrid.settings_form')
              ->toString(),
          ]),
        ];
      }
      else {
        $requirements['dds_sendgrid_api'] = [
          'title' => t('SendGrid API Key'),
          'severity' => REQUIREMENT_OK,
          'value' => t('API Secret Key saved'),
        ];
      }
      break;
  }

  return $requirements;
}