function CronForm::buildForm

Same name and namespace in other branches
  1. 11.x core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::buildForm()
  2. 10 core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::buildForm()
  3. 9 core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::buildForm()
  4. 8.9.x core/modules/system/src/Form/CronForm.php \Drupal\system\Form\CronForm::buildForm()

Overrides ConfigFormBase::buildForm

File

core/modules/system/src/Form/CronForm.php, line 67

Class

CronForm
Configure cron settings for this site.

Namespace

Drupal\system\Form

Code

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',
    ],
  ];
  if ($time_ago = $this->state
    ->get('system.cron_last')) {
    $status = '<p>' . $this->t('Last run: %time ago.', [
      '%time' => $this->dateFormatter
        ->formatTimeDiffSince($time_ago),
    ]) . '</p>';
  }
  else {
    $status = '<p>' . $this->t('Last run: never') . '</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('Install 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'),
    '#config_target' => 'system.cron:logging',
    '#description' => $this->t('Run times of individual cron jobs will be written to watchdog'),
  ];
  return parent::buildForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.