public function MaintenanceModeExempt::exempt in Maintenance Exempt 8
Determines whether a user has access to the site in maintenance mode.
Parameters
\Drupal\Core\Session\AccountInterface $account: The logged in user.
Return value
bool TRUE if the user should be exempted from maintenance mode.
Overrides MaintenanceMode::exempt
File
- src/
MaintenanceModeExempt.php, line 50
Class
- MaintenanceModeExempt
- Provides the default implementation of the maintenance mode service.
Namespace
Drupal\maintenance_exemptCode
public function exempt(AccountInterface $account) {
// Standard core behaviour - check user's permission.
if ($account
->hasPermission('access site in maintenance mode')) {
return TRUE;
}
// Check if the IP address should be exempted.
$client_ip = $this->request
->getClientIp();
if (in_array($client_ip, maintenance_exempt_get_ips())) {
return TRUE;
}
if (maintenance_exempt_by_cidr_notation($client_ip)) {
return TRUE;
}
// Check if the URL should be exempted.
$exempt_urls = \Drupal::config('maintenance_exempt.settings')
->get('exempt_urls');
// Check the actual URL.
$current_url = $this->request
->getPathInfo();
if ($this->pathMatcher
->matchPath($current_url, $exempt_urls)) {
return TRUE;
}
// Check the system path of aliased paths.
$current_path = \Drupal::service('path.current')
->getPath();
if ($this->pathMatcher
->matchPath($current_path, $exempt_urls)) {
return TRUE;
}
// Fetch the query string exemption key if there is one.
$config = \Drupal::config('maintenance_exempt.settings');
$key = $config
->get('query_key');
// Exemption status may be stored in the session.
if (isset($_SESSION['maintenance_exempt']) && $_SESSION['maintenance_exempt'] == $key) {
return TRUE;
}
if ($key && isset($_GET[$key])) {
$_SESSION['maintenance_exempt'] = $key;
return TRUE;
}
// No valid exemption, so user remains blocked.
return FALSE;
}