* Configure cron settings for this site.
*/
class CronForm extends FormBase {
+
use ConfigFormBaseTrait;
/**
/**
* The module handler service.
*
- * @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
$form['run'] = [
'#type' => 'submit',
'#value' => 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'] = [
$cron_url = $this->url('system.cron', ['key' => $this->state->get('system.cron_key')], ['absolute' => TRUE]);
$form['cron_url'] = [
- '#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', [':cron' => $cron_url, '@cron' => $cron_url]) . '</p>',
+ '#markup' => '<p>' . 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')) {
'#type' => 'checkbox',
'#title' => t('Detailed cron logging'),
'#default_value' => $this->config('system.cron')->get('logging'),
- '#description' => 'Run times of individual cron jobs will be written to watchdog',
+ '#description' => $this->t('Run times of individual cron jobs will be written to watchdog'),
];
$form['actions']['#type'] = 'actions';
}
/**
- * Runs cron and reloads the page.
+ * {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('system.cron')
->set('logging', $form_state->getValue('logging'))
->save();
drupal_set_message(t('The configuration options have been saved.'));
+ }
- // Run cron manually from Cron form.
+ /**
+ * Form submission handler for running cron manually.
+ */
+ public function runCron(array &$form, FormStateInterface $form_state) {
if ($this->cron->run()) {
- drupal_set_message(t('Cron ran successfully.'));
+ drupal_set_message($this->t('Cron ran successfully.'));
}
else {
- drupal_set_message(t('Cron run failed.'), 'error');
+ drupal_set_message($this->t('Cron run failed.'), 'error');
}
-
}
}