function CronForm::buildForm

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

Overrides FormInterface::buildForm

File

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

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',
        ],
    ];
    $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('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'),
        '#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;
}

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