EmailActionBase.php in Ubercart 8.4
File
uc_order/src/Plugin/RulesAction/EmailActionBase.php
View source
<?php
namespace Drupal\uc_order\Plugin\RulesAction;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Utility\Token;
use Drupal\rules\Core\RulesActionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class EmailActionBase extends RulesActionBase implements ContainerFactoryPluginInterface {
protected $currentUser;
protected $token;
protected $logger;
protected $mailManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user, Token $token, LoggerChannelFactoryInterface $logger, MailManagerInterface $mail_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->token = $token;
$this->logger = $logger;
$this->mailManager = $mail_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('token'), $container
->get('logger.factory'), $container
->get('plugin.manager.mail'));
}
public function messageFormats() {
$options = [];
$formats = filter_formats($this->currentUser);
foreach ($formats as $format) {
$options[$format
->id()] = $format
->label();
}
return $options;
}
public function invoiceOptions() {
return [
'print' => $this
->t('Show the business header and shipping method.'),
'admin-mail' => $this
->t('Show all of the above plus the help text, email text, and store footer.'),
'checkout-mail' => $this
->t('Show all of the above plus the "thank you" message.'),
];
}
public function templateOptions($custom = FALSE) {
$list = $this
->templateList();
$templates = array_combine($list, $list);
if ($custom) {
$templates[0] = $this
->t('Custom template');
}
return $templates;
}
protected function templateList() {
$invoke = \Drupal::moduleHandler()
->invokeAll('uc_invoice_templates');
$templates = array_combine($invoke, $invoke);
sort($templates);
return [
'admin',
'customer',
] + $templates;
}
}