public function QueueForm::buildForm in Notify 1.0.x
Same name and namespace in other branches
- 8 src/Form/QueueForm.php \Drupal\notify\Form\QueueForm::buildForm()
- 2.0.x src/Form/QueueForm.php \Drupal\notify\Form\QueueForm::buildForm()
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/ QueueForm.php, line 74
Class
- QueueForm
- Defines a form that configures forms module settings.
Namespace
Drupal\notify\FormCode
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('notify.settings');
$period = $config
->get('notify_period');
$since = $config
->get('notify_send_last') - $period;
$lastdate = \Drupal::service('date.formatter')
->format($since, 'short');
if (NULL !== $config
->get('notify_send_start')) {
$start = \Drupal::time()
->getRequestTime();
}
else {
$start = $config
->get('notify_send_start');
}
$start = $config
->get('notify_send_start') ?? 0;
$startdate = \Drupal::service('date.formatter')
->format($start, 'short');
$notify_send_last = $config
->get('notify_send_last');
if (!isset($notify_send_last)) {
$notify_send_last = \Drupal::time()
->getRequestTime();
}
$next_last = _notify_next_notificaton($notify_send_last);
if ($next_last == -1) {
$batch_msg = $this
->t('No more notifications scheduled');
}
elseif ($next_last == 0) {
$batch_msg = $this
->t('The next notification is scheduled for the next cron run');
}
else {
$next = \Drupal::service('date.formatter')
->format($next_last, 'short');
$batch_msg = $this
->t('The next notification is scheduled for the first cron run after ') . $next;
}
$form['process'] = [
'#type' => 'radios',
'#title' => $this
->t('Notification queue operations'),
'#default_value' => 0,
'#options' => [
$this
->t('Send batch now'),
$this
->t('Truncate queue'),
$this
->t('Override timestamp'),
],
'#description' => $this
->t('Select “Send batch now“ to send next batch of e-mails queued for notifications. Select “Truncate queue“ to empty queue of pending notification <em>without</em> sending e-mails. Select “Override timestamp“ to override the last notification timestamp. Press “Submit“ to execute.'),
];
$send_last = \Drupal::service('date.formatter')
->format($notify_send_last, 'custom', 'Y-m-d H:i:s');
$form['lastdate'] = [
'#type' => 'textfield',
'#title' => $this
->t('Last notification timestamp'),
'#default_value' => $send_last,
'#size' => 20,
'#maxlength' => 19,
'#description' => $this
->t('To explicitly set the last notification timestamp, change the value of this field and select the “Override timestamp“ option above, then press “Submit“ to execute.'),
];
$form['batch'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Status'),
'#collapsible' => TRUE,
];
list($np, $cp, $nn, $cn, $nu, $cu) = _notify_count($config);
$npcp = $np + $cp;
if ($npcp) {
$queue_msg = $this
->t('Notifications about at least @item queued', [
'@item' => \Drupal::translation()
->formatPlural($npcp, '1 item is', '@count items are'),
]);
}
else {
$queue_msg = $this
->t('No notifications queued');
}
$flagcnt = QueueForm::_Count($config
->get('notify_skip_nodes')) + QueueForm::_Count($config
->get('notify_skip_comments'));
if ($flagcnt) {
$skip_msg = $this
->t('@item flagged for skipping', [
'@item' => \Drupal::translation()
->formatPlural($flagcnt, '1 item is', '@count items are'),
]);
}
else {
$skip_msg = $this
->t('No item is flagged for skipping');
}
if ($np && $nu || $cp && $cu) {
$nonew_msg = '';
}
else {
$nonew_msg = $this
->t(', no notification about unpublished items are queued');
}
if ($nu + $cu) {
$unpub_msg = $this
->t('Unpublished: @nodeup and @commup', [
'@nodeup' => \Drupal::translation()
->formatPlural($nu, '1 node', '@count nodes'),
'@commup' => \Drupal::translation()
->formatPlural($cu, '1 comment', '@count comments'),
]) . $nonew_msg;
}
else {
$unpub_msg = $this
->t('No unpublished items');
}
$sent = $config
->get('notify_num_sent');
$fail = $config
->get('notify_num_failed');
$users = $config
->get('notify_users');
$batch_remain = $users ? count($users) : 0;
$creat_msg = $this
->t('There are @nodes and @comms created', [
'@nodes' => \Drupal::translation()
->formatPlural($np, '1 node', '@count nodes'),
'@comms' => \Drupal::translation()
->formatPlural($cp, '1 comment', '@count comments'),
]);
if ($nn + $cn) {
$publ_msg = $this
->t(', and in addition @noderp and @commrp published,', [
'@noderp' => \Drupal::translation()
->formatPlural($nn, '1 node', '@count nodes'),
'@commrp' => \Drupal::translation()
->formatPlural($cn, '1 comment', '@count comments'),
]);
}
else {
$publ_msg = '';
}
if ($batch_remain) {
$intrv_msg = $this
->t('between @last and @start', [
'@last' => $lastdate,
'@start' => $startdate,
]);
$sent_msg = $this
->t('Batch not yet complete. So far @sent has been sent (@fail, @remain to go)', [
'@sent' => \Drupal::translation()
->formatPlural($sent, '1 e-mail', '@count e-mails'),
'@fail' => \Drupal::translation()
->formatPlural($fail, '1 failure', '@count failures'),
'@remain' => \Drupal::translation()
->formatPlural($batch_remain, '1 user', '@count users'),
]);
}
else {
$intrv_msg = $this
->t('since @last', [
'@last' => $lastdate,
]);
$sent_msg = $this
->t('Last batch:') . ' ';
if ($sent == 0) {
$sent_msg = $this
->t('No e-mails were sent');
}
else {
$sent_msg .= $this
->t('sent @sent', [
'@sent' => \Drupal::translation()
->formatPlural($sent, '1 e-mail', '@count e-mails'),
]);
}
if ($fail > 0) {
$sent_msg .= ', ' . $this
->t('@fail', [
'@fail' => \Drupal::translation()
->formatPlural($fail, '1 failure', '@count failures'),
]);
}
elseif ($sent) {
$sent_msg .= ', ' . $this
->t('no failures');
}
}
$mailsystem = $config
->get('mail_system') ?? NULL;
$ms = isset($mailsystem['default-system']) ? $mailsystem['default-system'] : $this
->t('system default');
$form['batch']['schedule'] = [
'#markup' => $creat_msg . $publ_msg . ' ' . $intrv_msg . '.<br>' . $unpub_msg . '.<br>' . $queue_msg . '.<br>' . $skip_msg . '.<br>' . $sent_msg . '.<br>' . $batch_msg . '.<br>' . $this
->t('Default MailSystem: ') . $ms . '.',
];
return parent::buildForm($form, $form_state);
}