Skip to content
Snippets Groups Projects

Issue #3494284: Allow to use key module for Sendgrid API key

Merged Manuel Egío requested to merge issue/sendgrid-3494284:1.0.x into 1.0.x
8 files
+ 301
17
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 17
2
@@ -3,6 +3,7 @@
namespace Drupal\sendgrid\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
@@ -23,22 +24,31 @@ class SettingsForm extends ConfigFormBase {
*/
protected $filterManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.filter')
$container->get('plugin.manager.filter'),
$container->get('module_handler')
);
}
/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $config_factory, FilterPluginManager $filter_manager) {
public function __construct(ConfigFactoryInterface $config_factory, FilterPluginManager $filter_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($config_factory);
$this->filterManager = $filter_manager;
$this->moduleHandler = $module_handler;
}
/**
@@ -72,6 +82,11 @@ class SettingsForm extends ConfigFormBase {
]),
'#default_value' => $config->get('api_key'),
];
// Add key_select element if key module is enabled.
if ($this->moduleHandler->moduleExists('key')) {
$form['api_key']['#type'] = 'key_select';
$form['api_key']['#key_filters'] = ['type' => 'authentication'];
}
$form['debug_mode'] = [
'#title' => $this->t('Enable Debug Mode'),
Loading