public function CronForm::buildForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::buildForm()
- 9 core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::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
- core/
modules/ system/ src/ Form/ CronForm.php, line 104
Class
- CronForm
- Configure cron settings for this site.
Namespace
Drupal\system\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#markup' => '<p>' . $this
->t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
];
$form['run'] = [
'#type' => 'submit',
'#value' => $this
->t('Run cron'),
'#submit' => [
'::runCron',
],
];
$status = '<p>' . $this
->t('Last run: %time ago.', [
'%time' => $this->dateFormatter
->formatTimeDiffSince($this->state
->get('system.cron_last')),
]) . '</p>';
$form['status'] = [
'#markup' => $status,
];
$cron_url = Url::fromRoute('system.cron', [
'key' => $this->state
->get('system.cron_key'),
], [
'absolute' => TRUE,
])
->toString();
$form['cron_url'] = [
'#markup' => '<p>' . $this
->t('To run cron from outside the site, go to <a href=":cron" class="system-cron-settings__link">@cron</a>', [
':cron' => $cron_url,
'@cron' => $cron_url,
]) . '</p>',
];
if (!$this->moduleHandler
->moduleExists('automated_cron')) {
$form['automated_cron'] = [
'#markup' => $this
->t('Enable the <em>Automated Cron</em> module to allow cron execution at the end of a server response.'),
];
}
$form['cron'] = [
'#title' => $this
->t('Cron settings'),
'#type' => 'details',
'#open' => TRUE,
];
$form['cron']['logging'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Detailed cron logging'),
'#default_value' => $this
->config('system.cron')
->get('logging'),
'#description' => $this
->t('Run times of individual cron jobs will be written to watchdog'),
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
'#button_type' => 'primary',
];
return $form;
}