class WebformEmailProvider in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformEmailProvider.php \Drupal\webform\WebformEmailProvider
Manages and provides HTML email support.
Hierarchy
- class \Drupal\webform\WebformEmailProvider implements WebformEmailProviderInterface
Expanded class hierarchy of WebformEmailProvider
1 string reference to 'WebformEmailProvider'
1 service uses WebformEmailProvider
File
- src/
WebformEmailProvider.php, line 12
Namespace
Drupal\webformView source
class WebformEmailProvider implements WebformEmailProviderInterface {
/**
* The configuration object factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Mail manager service.
*
* @var \Drupal\Core\Mail\MailManagerInterface
*/
protected $mailManager;
/**
* Constructs a WebformEmailProvider object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration object factory.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler class to use for loading includes.
* @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
* Mail manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, MailManagerInterface $mail_manager) {
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->mailManager = $mail_manager;
}
/**
* {@inheritdoc}
*/
public function getModules() {
return [
// Mail System - https://www.drupal.org/project/mailsystem
'mailsystem',
// SMTP Authentication Support - https://www.drupal.org/project/smtp
'smtp',
];
}
/**
* {@inheritdoc}
*/
public function check() {
// Don't override the system.mail.interface.webform if the default interface
// is the 'test_mail_collector'.
if ($this->configFactory
->get('system.mail')
->get('interface.default') === 'test_mail_collector') {
return $this
->uninstall();
}
// Check if a contrib module is handling sending email.
$mail_modules = $this
->getModules();
foreach ($mail_modules as $module) {
if ($this
->moduleEnabled($module)) {
return $this
->uninstall();
}
}
// Finally, check if the default mail interface and see if it still uses the
// php_mail. This check allow unknown contrib modules to handle sending
// HTML emails.
if ($this->configFactory
->get('system.mail')
->get('interface.default') === 'php_mail') {
return $this
->install();
}
else {
return $this
->uninstall();
}
}
/**
* {@inheritdoc}
*/
public function installed() {
return $this->configFactory
->get('system.mail')
->get('interface.webform') === 'webform_php_mail';
}
/**
* {@inheritdoc}
*/
public function install() {
$config = $this->configFactory
->getEditable('system.mail');
$mail_plugins = $config
->get('interface');
if (!isset($mail_plugins['webform']) || $mail_plugins['webform'] !== 'webform_php_mail') {
$mail_plugins['webform'] = 'webform_php_mail';
$config
->set('interface', $mail_plugins)
->save();
}
}
/**
* {@inheritdoc}
*/
public function uninstall() {
$config = $this->configFactory
->getEditable('system.mail');
$mail_plugins = $config
->get('interface');
if (isset($mail_plugins['webform'])) {
unset($mail_plugins['webform']);
$config
->set('interface', $mail_plugins)
->save();
}
}
/**
* {@inheritdoc}
*/
public function getModule() {
if ($this
->installed()) {
return 'webform';
}
else {
$modules = $this
->getModules();
foreach ($modules as $module) {
if ($this
->moduleEnabled($module)) {
return $module;
}
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getModuleName() {
return ($module = $this
->getModule()) ? $this->moduleHandler
->getName($module) : FALSE;
}
/**
* {@inheritdoc}
*/
public function moduleEnabled($module) {
// Make sure module exists and is installed.
if (!$this->moduleHandler
->moduleExists($module)) {
return FALSE;
}
// Make sure SMTP module is enabled.
if ($module === 'smtp' && !$this->configFactory
->get('smtp.settings')
->get('smtp_on')) {
return FALSE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getMailPluginId() {
$config = $this->configFactory
->get('system.mail');
return $config
->get('interface.webform') ?: $config
->get('interface.default') ?: FALSE;
}
/**
* {@inheritdoc}
*/
public function getMailPluginDefinition() {
$plugin_id = $this
->getMailPluginId();
return $plugin_id && $this->mailManager
->hasDefinition($plugin_id) ? $this->mailManager
->getDefinition($plugin_id) : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WebformEmailProvider:: |
protected | property | The configuration object factory. | |
WebformEmailProvider:: |
protected | property | Mail manager service. | |
WebformEmailProvider:: |
protected | property | The module handler service. | |
WebformEmailProvider:: |
public | function |
Check if the Webform module should provide support for sending HTML emails. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Get the mail back-end plugin definition. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Get the mail back-end plugin id. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Get the HTML email provider module machine name. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Get the HTML email provider human readable module name. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Get list of known contrib module that support HTML email. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Install webform's PHP mail handler which supports sending HTML emails. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Check if webform email handler is installed. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Determine if mail module is installed and enabled. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function |
Uninstall webform's PHP mail handler which supports sending HTML emails. Overrides WebformEmailProviderInterface:: |
|
WebformEmailProvider:: |
public | function | Constructs a WebformEmailProvider object. |