class QueueMailSettingsForm in Queue Mail 8
Configures module's settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\queue_mail\Form\QueueMailSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of QueueMailSettingsForm
1 string reference to 'QueueMailSettingsForm'
File
- src/
Form/ QueueMailSettingsForm.php, line 16
Namespace
Drupal\queue_mail\FormView source
class QueueMailSettingsForm extends ConfigFormBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The redirect destination.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* Constructs a new QueueMailSettingsForm.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Module handler service.
* @param Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
* The redirect destination.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, RedirectDestinationInterface $redirect_destination) {
parent::__construct($config_factory);
$this->moduleHandler = $module_handler;
$this->redirectDestination = $redirect_destination;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('redirect.destination'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'queue_mail_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'queue_mail.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('queue_mail.settings');
$form['queue_status'] = [
'#type' => 'item',
'#title' => $this
->t('Queue status'),
'#markup' => $this
->formatPlural(_queue_mail_get_queue()
->numberOfItems(), '1 mail currently queued for sending.', '@count mails currently queued for sending.'),
'#description' => $this
->t('Sending of queued mails happens on cron. You can <a href="@cron_link">run cron manually</a>.', [
'@cron_link' => Url::fromRoute('system.run_cron', [], [
'query' => $this->redirectDestination
->getAsArray(),
])
->toString(),
]),
];
$form['queue_mail_keys'] = [
'#type' => 'textarea',
'#title' => $this
->t('Mail IDs to queue'),
'#description' => $this
->t('Enter each mail ID to queue on a separate line. Use <strong>*</strong> to do a wildcard match.') . '<br/>' . $this
->t('Mail IDs are a combination of the first and second arguments sent to <em>drupal_mail</em> when a module sends an email. E.g. <em>user_mail</em>, <em>register_pending_approval_admin</em>') . '<br />' . $this
->t('For example, to queue all mails sent by the User module, enter: <em>user_*</em> above, to just queue password recovery emails enter: <em>user_password_reset</em>'),
'#default_value' => $config
->get('queue_mail_keys'),
];
// Get a list of modules that implement hook_mail.
$mail_modules = $this->moduleHandler
->getImplementations('mail');
$rows = [];
foreach ($mail_modules as $name) {
$row = [];
$row[] = $name;
$row[] = $name . '_*';
$rows[] = $row;
}
$headers = [
$this
->t('Module name'),
$this
->t('Mail ID prefix'),
];
$form['tables'] = [
'#type' => 'table',
'#caption' => $this
->t('The following modules send emails. The contents of the second column can be used in the options above to queue the sending of those emails.'),
'#header' => $headers,
'#rows' => $rows,
'#empty' => $this
->t('No tables available.'),
];
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced settings'),
'#collapsed' => TRUE,
];
$options = [];
for ($i = 5; $i <= 240; $i += 5) {
$options[$i] = $this
->formatPlural($i, '1 second', '@count seconds');
}
$form['advanced']['queue_mail_queue_time'] = [
'#type' => 'select',
'#title' => $this
->t('Queue processing time (max)'),
'#description' => $this
->t('How much time in seconds to allow queue mail to send emails for on cron. Warning if you set a very high limit your cron run could timeout and never complete.'),
'#options' => $options,
'#default_value' => $config
->get('queue_mail_queue_time'),
];
$form['advanced']['threshold'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this
->t('Queue retry threshold'),
'#default_value' => $config
->get('threshold'),
'#description' => $this
->t('How many times to retry before deleting an item.'),
];
$form['advanced']['requeue_interval'] = [
'#type' => 'number',
'#min' => 0,
'#title' => $this
->t('Requeue interval'),
'#default_value' => $config
->get('requeue_interval'),
'#field_suffix' => $this
->t('seconds'),
'#description' => $this
->t('How long to wait in seconds before retrying failed emails.'),
];
$form['advanced']['queue_mail_queue_wait_time'] = [
'#type' => 'number',
'#title' => $this
->t('Wait time per item'),
'#description' => $this
->t('How long to wait in seconds in between the processing of each item. This value can not be bigger than "Queue processing time" value.'),
'#step' => 1,
'#min' => 0,
'#field_suffix' => $this
->t('seconds'),
'#default_value' => $config
->get('queue_mail_queue_wait_time') ?: 0,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$queue_mail_queue_time = $form_state
->getValue('queue_mail_queue_time');
$queue_mail_queue_wait_time = $form_state
->getValue('queue_mail_queue_wait_time');
if ($queue_mail_queue_time < $queue_mail_queue_wait_time) {
$form_state
->setErrorByName('queue_mail_queue_wait_time', $this
->t('"Wait time per item" value can not be bigger than "Queue processing time" value.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('queue_mail.settings')
->set('queue_mail_keys', $form_state
->getValue('queue_mail_keys'))
->set('queue_mail_queue_time', $form_state
->getValue('queue_mail_queue_time'))
->set('threshold', $form_state
->getValue('threshold'))
->set('requeue_interval', $form_state
->getValue('requeue_interval'))
->set('queue_mail_queue_wait_time', $form_state
->getValue('queue_mail_queue_wait_time'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
QueueMailSettingsForm:: |
protected | property | The module handler. | |
QueueMailSettingsForm:: |
protected | property |
The redirect destination. Overrides RedirectDestinationTrait:: |
|
QueueMailSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
QueueMailSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
QueueMailSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
QueueMailSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
QueueMailSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
QueueMailSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
QueueMailSettingsForm:: |
public | function |
Constructs a new QueueMailSettingsForm. Overrides ConfigFormBase:: |
|
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |