You are here

class LanguageAwareSendMailQueueWorker in Queue Mail 8

Sends emails from queue with language support.

Hierarchy

Expanded class hierarchy of LanguageAwareSendMailQueueWorker

1 file declares its use of LanguageAwareSendMailQueueWorker
queue_mail_language.module in modules/queue_mail_language/queue_mail_language.module
The Queue Mail Language module.

File

modules/queue_mail_language/src/Plugin/QueueWorker/LanguageAwareSendMailQueueWorker.php, line 20

Namespace

Drupal\queue_mail_language\Plugin\QueueWorker
View source
class LanguageAwareSendMailQueueWorker extends SendMailQueueWorker {

  /**
   * The configurable language manager.
   *
   * @var \Drupal\language\ConfigurableLanguageManagerInterface
   */
  protected $languageManager;

  /**
   * The queue mail language negotiator.
   *
   * @var \Drupal\queue_mail_language\QueueMailLanguageNegotiator
   */
  protected $queueMailLanguageNegotiator;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($container
      ->get('theme.manager'), $container
      ->get('theme.initialization'), $container
      ->get('plugin.manager.mail'), $container
      ->get('logger.factory'), $container
      ->get('config.factory'), $container
      ->get('queue'), $container
      ->get('module_handler'), $container
      ->get('language_manager'), $container
      ->get('queue_mail.language_negotiator'));
  }

  /**
   * {@inheritdoc}
   */
  public function __construct(ThemeManagerInterface $theme_manager, ThemeInitializationInterface $theme_init, MailManagerInterface $mail_manager, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, ContainerAwareInterface $queue_factory, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager, QueueMailLanguageNegotiator $queue_mail_language_negotiator) {
    parent::__construct($theme_manager, $theme_init, $mail_manager, $logger_factory, $config_factory, $queue_factory, $module_handler);
    $this->languageManager = $language_manager;
    $this->queueMailLanguageNegotiator = $queue_mail_language_negotiator;
  }

  /**
   * {@inheritdoc}
   */
  protected function setMailLanguage(array $message) {
    $default_langcode = $this->languageManager
      ->getDefaultLanguage()
      ->getId();
    if ($message['langcode'] !== $default_langcode) {
      $this
        ->setNegotiatorLanguage($message['langcode']);
    }
    return $default_langcode;
  }

  /**
   * {@inheritdoc}
   */
  protected function setActiveLanguage(array $message, $langcode) {
    if ($message['langcode'] !== $langcode) {
      $this
        ->setNegotiatorLanguage($langcode);
    }
  }

  /**
   * Sets the queue mail negotiator language.
   *
   * @param string $langcode
   *   The new language code.
   */
  protected function setNegotiatorLanguage($langcode) {
    if ($this->languageManager
      ->getNegotiator() !== $this->queueMailLanguageNegotiator) {
      $this->languageManager
        ->setNegotiator($this->queueMailLanguageNegotiator);
    }
    $this->queueMailLanguageNegotiator
      ->setLanguageCode($langcode);

    // Needed to re-run language negotiation.
    $this->languageManager
      ->reset();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageAwareSendMailQueueWorker::$languageManager protected property The configurable language manager.
LanguageAwareSendMailQueueWorker::$queueMailLanguageNegotiator protected property The queue mail language negotiator.
LanguageAwareSendMailQueueWorker::create public static function Creates an instance of the plugin. Overrides SendMailQueueWorker::create
LanguageAwareSendMailQueueWorker::setActiveLanguage protected function Restores back the negotiated language. Overrides SendMailQueueWorker::setActiveLanguage
LanguageAwareSendMailQueueWorker::setMailLanguage protected function Sets language from the message. Overrides SendMailQueueWorker::setMailLanguage
LanguageAwareSendMailQueueWorker::setNegotiatorLanguage protected function Sets the queue mail negotiator language.
LanguageAwareSendMailQueueWorker::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides SendMailQueueWorker::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SendMailQueueWorker::$activeTheme protected property Active theme.
SendMailQueueWorker::$config protected property Queue mail configuration.
SendMailQueueWorker::$logger protected property Logger.
SendMailQueueWorker::$mailManager protected property Mail manager.
SendMailQueueWorker::$moduleHandler protected property The module handler to invoke the alter hook.
SendMailQueueWorker::$queue protected property Queue for sending mails.
SendMailQueueWorker::$themeInitialization protected property Theme initialization.
SendMailQueueWorker::$themeManager protected property Theme manager.
SendMailQueueWorker::messageHasAnotherTheme protected function Checks if message has been generated using another theme.
SendMailQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
SendMailQueueWorker::processRetryLimit protected function Retry limit handler.
SendMailQueueWorker::setActiveTheme protected function Restore back theme that is used by default.
SendMailQueueWorker::setMailTheme protected function Set theme from the theme.
SendMailQueueWorker::waitBetweenSending protected function Wait between items processing.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.