class MaintenanceMode

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Site/MaintenanceMode.php \Drupal\Core\Site\MaintenanceMode
  2. 8.9.x core/lib/Drupal/Core/Site/MaintenanceMode.php \Drupal\Core\Site\MaintenanceMode
  3. 11.x core/lib/Drupal/Core/Site/MaintenanceMode.php \Drupal\Core\Site\MaintenanceMode

Provides the default implementation of the maintenance mode service.

Hierarchy

Expanded class hierarchy of MaintenanceMode

1 string reference to 'MaintenanceMode'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses MaintenanceMode
maintenance_mode in core/core.services.yml
Drupal\Core\Site\MaintenanceMode

File

core/lib/Drupal/Core/Site/MaintenanceMode.php, line 14

Namespace

Drupal\Core\Site
View source
class MaintenanceMode implements MaintenanceModeInterface {
  
  /**
   * The state.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;
  
  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;
  
  /**
   * Constructs a new maintenance mode service.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory) {
    $this->state = $state;
    $this->config = $config_factory;
  }
  
  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    if (!$this->state
      ->get('system.maintenance_mode')) {
      return FALSE;
    }
    if ($route = $route_match->getRouteObject()) {
      if ($route->getOption('_maintenance_access')) {
        return FALSE;
      }
    }
    return TRUE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function exempt(AccountInterface $account) {
    return $account->hasPermission('access site in maintenance mode');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getSiteMaintenanceMessage() {
    return new FormattableMarkup($this->config
      ->get('system.maintenance')
      ->get('message'), [
      '@site' => $this->config
        ->get('system.site')
        ->get('name'),
    ]);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
MaintenanceMode::$config protected property The configuration factory.
MaintenanceMode::$state protected property The state.
MaintenanceMode::applies public function Returns whether the site is in maintenance mode. Overrides MaintenanceModeInterface::applies
MaintenanceMode::exempt public function Determines whether a user has access to the site in maintenance mode. Overrides MaintenanceModeInterface::exempt
MaintenanceMode::getSiteMaintenanceMessage public function Gets the site maintenance message. Overrides MaintenanceModeInterface::getSiteMaintenanceMessage
MaintenanceMode::__construct public function Constructs a new maintenance mode service.

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