summaryrefslogtreecommitdiffstats
path: root/core/modules/overlay/lib/Drupal/overlay/Access/DismissMessageAccessCheck.php
blob: 3c74bab0f9236b5f9a2ca297b1c5edaba18dc32b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

/**
 * @file
 * Contains \Drupal\overlay\Access\DismissMessageAccessCheck
 */

namespace Drupal\overlay\Access;

use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;

/**
 * Provides an access check for overlay user dismiss message routes.
 */
class DismissMessageAccessCheck implements AccessCheckInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return array_key_exists('_access_overlay_dismiss_message', $route->getRequirements());
  }

  /**
   * {@inheritdoc}
   */
  public function access(Route $route, Request $request) {
    $account = $request->attributes->get('account');
    if (!user_access('access overlay', $account)) {
      return static::DENY;
    }
    // It's unlikely, but possible that "access overlay" permission is granted
    // to the anonymous role. In this case, we do not display the message to
    // disable the overlay, so there is nothing to dismiss.
    if (!$account->id()) {
      return static::DENY;
    }
    return static::ALLOW;
  }

}