public function NodeTabForm::buildForm in Simplenews 8.2
Same name and namespace in other branches
- 8 src/Form/NodeTabForm.php \Drupal\simplenews\Form\NodeTabForm::buildForm()
- 3.x src/Form/NodeTabForm.php \Drupal\simplenews\Form\NodeTabForm::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 FormInterface::buildForm
File
- src/
Form/ NodeTabForm.php, line 89
Class
- NodeTabForm
- Configure simplenews subscriptions of a user.
Namespace
Drupal\simplenews\FormCode
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
$config = $this
->config('simplenews.settings');
$status = $node->simplenews_issue->status;
$summary = $this->spoolStorage
->issueSummary($node);
$form['#title'] = $this
->t('<em>Newsletter issue</em> @title', [
'@title' => $node
->getTitle(),
]);
// We will need the node.
$form_state
->set('node', $node);
// Show newsletter sending options if newsletter has not been send yet.
// If send a notification is shown.
if ($status == SIMPLENEWS_STATUS_SEND_NOT) {
$form['test'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Test'),
];
$form['test']['test_address'] = [
'#type' => 'textfield',
'#title' => $this
->t('Test email addresses'),
'#description' => $this
->t('A comma-separated list of email addresses to be used as test addresses.'),
'#default_value' => $this->currentUser
->getEmail(),
'#size' => 60,
'#maxlength' => 128,
];
$form['test']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Send test newsletter issue'),
'#name' => 'send_test',
'#submit' => [
'::submitTestMail',
],
'#validate' => [
'::validateTestAddress',
],
];
$form['send'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Send'),
];
// Add some text to describe the send situation.
$form['send']['count'] = [
'#type' => 'item',
'#markup' => $this
->t('Send newsletter issue to @count subscribers.', [
'@count' => $summary['count'],
]),
];
if (!$node
->isPublished()) {
$send_text = $this
->t('Mails will be sent when the issue is published.');
$button_text = $this
->t('Send on publish');
}
elseif (!$config
->get('mail.use_cron')) {
$send_text = $this
->t('Mails will be sent immediately.');
}
else {
$send_text = $this
->t('Mails will be sent when cron runs.');
}
$form['send']['method'] = [
'#type' => 'item',
'#markup' => $send_text,
];
$form['send']['send'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $button_text ?? $this
->t('Send now'),
];
}
else {
$form['status'] = [
'#type' => 'item',
'#title' => $summary['description'],
];
if ($status != SIMPLENEWS_STATUS_SEND_READY) {
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['stop'] = [
'#type' => 'submit',
'#submit' => [
'::submitStop',
],
'#value' => $this
->t('Stop sending'),
];
}
}
return $form;
}