public function QueueMailSettingsForm::buildForm in Queue Mail 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ QueueMailSettingsForm.php, line 79
Class
- QueueMailSettingsForm
- Configures module's settings.
Namespace
Drupal\queue_mail\FormCode
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);
}