class CronAccessCheck

Same name in other branches
  1. 8.9.x core/modules/system/src/Access/CronAccessCheck.php \Drupal\system\Access\CronAccessCheck
  2. 10 core/modules/system/src/Access/CronAccessCheck.php \Drupal\system\Access\CronAccessCheck
  3. 11.x core/modules/system/src/Access/CronAccessCheck.php \Drupal\system\Access\CronAccessCheck

Access check for cron routes.

Hierarchy

Expanded class hierarchy of CronAccessCheck

1 string reference to 'CronAccessCheck'
system.services.yml in core/modules/system/system.services.yml
core/modules/system/system.services.yml
1 service uses CronAccessCheck
access_check.cron in core/modules/system/system.services.yml
Drupal\system\Access\CronAccessCheck

File

core/modules/system/src/Access/CronAccessCheck.php, line 11

Namespace

Drupal\system\Access
View source
class CronAccessCheck implements AccessInterface {
    
    /**
     * Checks access.
     *
     * @param string $key
     *   The cron key.
     *
     * @return \Drupal\Core\Access\AccessResultInterface
     *   The access result.
     */
    public function access($key) {
        if ($key != \Drupal::state()->get('system.cron_key')) {
            \Drupal::logger('cron')->notice('Cron could not run because an invalid key was used.');
            return AccessResult::forbidden()->setCacheMaxAge(0);
        }
        elseif (\Drupal::state()->get('system.maintenance_mode')) {
            \Drupal::logger('cron')->notice('Cron could not run because the site is in maintenance mode.');
            return AccessResult::forbidden()->setCacheMaxAge(0);
        }
        return AccessResult::allowed()->setCacheMaxAge(0);
    }

}

Members

Title Sort descending Modifiers Object type Summary
CronAccessCheck::access public function Checks access.

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