class MailsystemManager in Mail System 8.4
Factory for creating mail system objects based on BasePlugin's.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements PluginManagerInterface uses DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
- class \Drupal\Core\Mail\MailManager implements MailManagerInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\mailsystem\MailsystemManager
- class \Drupal\Core\Mail\MailManager implements MailManagerInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
Expanded class hierarchy of MailsystemManager
1 file declares its use of MailsystemManager
- AdminForm.php in src/
Form/ AdminForm.php
File
- src/
MailsystemManager.php, line 15
Namespace
Drupal\mailsystemView source
class MailsystemManager extends MailManager {
/**
* Constants used for the configuration.
*/
const MAILSYSTEM_TYPE_SENDING = 'sender';
const MAILSYSTEM_TYPE_FORMATTING = 'formatter';
const MAILSYSTEM_MODULES_CONFIG = 'modules';
/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* The theme initialization.
*
* @var \Drupal\Core\Theme\ThemeInitializationInterface
*/
protected $themeInitialization;
/**
* Sets the theme manager for mailsystem.
*
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function setThemeManager(ThemeManagerInterface $theme_manager) {
$this->themeManager = $theme_manager;
}
/**
* Sets the theme initialization for mailsystem.
*
* @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization
* The theme initialization.
*/
public function setThemeInitialization(ThemeInitializationInterface $theme_initialization) {
$this->themeInitialization = $theme_initialization;
}
/**
* {@inheritdoc}
*/
public function mail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE) {
// Switch the theme to the configured mail theme.
$mail_theme = $this
->getMailTheme();
$current_active_theme = $this->themeManager
->getActiveTheme();
if ($mail_theme && $mail_theme != $current_active_theme
->getName()) {
$this->themeManager
->setActiveTheme($this->themeInitialization
->initTheme($mail_theme));
}
try {
$message = parent::mail($module, $key, $to, $langcode, $params, $reply, $send);
} finally {
// Revert the active theme, this is done inside a finally block so it is
// executed even if an exception is thrown during sending a mail.
if ($mail_theme != $current_active_theme
->getName()) {
$this->themeManager
->setActiveTheme($current_active_theme);
}
}
return $message;
}
/**
* {@inheritdoc}
*/
public function getInstance(array $options) {
$module = isset($options['module']) ? $options['module'] : 'default';
$key = isset($options['key']) ? $options['key'] : '';
return new Adapter($this
->getPluginInstance($module, $key, static::MAILSYSTEM_TYPE_FORMATTING), $this
->getPluginInstance($module, $key, static::MAILSYSTEM_TYPE_SENDING));
}
/**
* Get a Mail-Plugin instance and return it.
*
* @param string $module
* Module name which is going to send and email.
* @param string $key
* (optional) The ID if the email which is being sent.
* @param string $type
* (optional) A subtype, like 'sending' or 'formatting'.
* Use \Drupal\mailsystem\MailsystemManager\MAILSYSTEM_TYPE_SENDING and
* \Drupal\mailsystem\MailsystemManager\MAILSYSTEM_TYPE_FORMATTING.
*
* @return \Drupal\Core\Mail\MailInterface
* A mail plugin instance.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
protected function getPluginInstance($module, $key = '', $type = '') {
$plugin_id = NULL;
// List of message ids which can be configured.
$message_id_list = [
self::MAILSYSTEM_MODULES_CONFIG . '.' . $module . '.' . $key . '.' . $type,
self::MAILSYSTEM_MODULES_CONFIG . '.' . $module . '.none.' . $type,
self::MAILSYSTEM_MODULES_CONFIG . '.' . $module . '.' . $type,
'defaults.' . $type,
'defaults',
];
$config = $this->configFactory
->get('mailsystem.settings');
foreach ($message_id_list as $message_id) {
$plugin_id = $config
->get($message_id);
if (!is_null($plugin_id)) {
break;
}
}
// If there is no instance cached, try to create one.
if (empty($this->instances[$plugin_id])) {
$plugin = $this
->createInstance($plugin_id);
if ($plugin instanceof MailInterface) {
$this->instances[$plugin_id] = $plugin;
}
else {
throw new InvalidPluginDefinitionException($plugin_id, new FormattableMarkup('Class %class does not implement interface %interface', [
'%class' => get_class($plugin),
'%interface' => 'Drupal\\Core\\Mail\\MailInterface',
]));
}
}
return $this->instances[$plugin_id];
}
/**
* Retrieves the key of the theme used to render the emails.
*/
public function getMailTheme() {
$theme = $this->configFactory
->get('mailsystem.settings')
->get('theme');
switch ($theme) {
case 'default':
$theme = $this->configFactory
->get('system.theme')
->get('default');
break;
case 'current':
$theme = $this->themeManager
->getActiveTheme()
->getName();
break;
case 'domain':
// Fetch the theme for the current domain.
// @todo: Reimplement this as soon as module port or similar module is around.
if (FALSE && \Drupal::moduleHandler()
->moduleExists('domain_theme')) {
// Assign the selected theme, based on the active domain.
global $_domain;
$domain_theme = domain_theme_lookup($_domain['domain_id']);
// The above returns -1 on failure.
$theme = $domain_theme != -1 ? $domain_theme['theme'] : $this->themeManager
->getActiveTheme()
->getName();
}
break;
}
return $theme;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPluginManager:: |
protected | property | Additional namespaces the annotation discovery mechanism should scan for annotation definitions. | |
DefaultPluginManager:: |
protected | property | Name of the alter hook if one should be invoked. | |
DefaultPluginManager:: |
protected | property | The cache key. | |
DefaultPluginManager:: |
protected | property | An array of cache tags to use for the cached definitions. | |
DefaultPluginManager:: |
protected | property | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. | 9 |
DefaultPluginManager:: |
protected | property | The module handler to invoke the alter hook. | 1 |
DefaultPluginManager:: |
protected | property | An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations. | |
DefaultPluginManager:: |
protected | property | The name of the annotation that contains the plugin definition. | |
DefaultPluginManager:: |
protected | property | The interface each plugin should implement. | 1 |
DefaultPluginManager:: |
protected | property | The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace. | |
DefaultPluginManager:: |
protected | function | Invokes the hook to alter the definitions if the alter hook is set. | 1 |
DefaultPluginManager:: |
protected | function | Sets the alter hook name. | |
DefaultPluginManager:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
5 |
DefaultPluginManager:: |
protected | function | Extracts the provider from a plugin definition. | |
DefaultPluginManager:: |
protected | function | Finds plugin definitions. | 7 |
DefaultPluginManager:: |
private | function | Fix the definitions of context-aware plugins. | |
DefaultPluginManager:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
protected | function | Returns the cached plugin definitions of the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryTrait:: |
2 |
DefaultPluginManager:: |
protected | function |
Gets the plugin discovery. Overrides PluginManagerBase:: |
12 |
DefaultPluginManager:: |
protected | function |
Gets the plugin factory. Overrides PluginManagerBase:: |
|
DefaultPluginManager:: |
public | function | Performs extra processing on plugin definitions. | 13 |
DefaultPluginManager:: |
protected | function | Determines if the provider of a definition exists. | 3 |
DefaultPluginManager:: |
public | function | Initialize the cache backend. | |
DefaultPluginManager:: |
protected | function | Sets a cache of plugin definitions for the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
Disable the use of caches. Overrides CachedDiscoveryInterface:: |
1 |
DiscoveryCachedTrait:: |
protected | property | Cached definitions array. | 1 |
DiscoveryCachedTrait:: |
public | function |
Overrides DiscoveryTrait:: |
3 |
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | ||
MailManager:: |
protected | property | The config factory. | |
MailManager:: |
protected | property | List of already instantiated mail plugins. | |
MailManager:: |
protected | property | The logger factory. | |
MailManager:: |
protected | property | The renderer. | |
MailManager:: |
public | function | Composes and optionally sends an email message. | 1 |
MailManager:: |
public | function |
Constructs the MailManager object. Overrides DefaultPluginManager:: |
|
MailsystemManager:: |
protected | property | The theme initialization. | |
MailsystemManager:: |
protected | property | The theme manager. | |
MailsystemManager:: |
public | function |
Overrides PluginManagerBase::getInstance(). Overrides MailManager:: |
|
MailsystemManager:: |
public | function | Retrieves the key of the theme used to render the emails. | |
MailsystemManager:: |
protected | function | Get a Mail-Plugin instance and return it. | |
MailsystemManager:: |
public | function |
Composes and optionally sends an email message. Overrides MailManager:: |
|
MailsystemManager:: |
constant | |||
MailsystemManager:: |
constant | |||
MailsystemManager:: |
constant | Constants used for the configuration. | ||
MailsystemManager:: |
public | function | Sets the theme initialization for mailsystem. | |
MailsystemManager:: |
public | function | Sets the theme manager for mailsystem. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides FactoryInterface:: |
12 |
PluginManagerBase:: |
protected | function | Allows plugin managers to specify custom behavior if a plugin is not found. | 1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UseCacheBackendTrait:: |
protected | property | Cache backend instance. | |
UseCacheBackendTrait:: |
protected | property | Flag whether caches should be used or skipped. | |
UseCacheBackendTrait:: |
protected | function | Fetches from the cache backend, respecting the use caches flag. | 1 |
UseCacheBackendTrait:: |
protected | function | Stores data in the persistent cache, respecting the use caches flag. |