You are here

class PreviewLinkSessionExistsAccessCheck in Preview Link 2.x

Same name and namespace in other branches
  1. 2.0.x src/Access/PreviewLinkSessionExistsAccessCheck.php \Drupal\preview_link\Access\PreviewLinkSessionExistsAccessCheck

Checks whether the user has a session.

Hierarchy

Expanded class hierarchy of PreviewLinkSessionExistsAccessCheck

1 string reference to 'PreviewLinkSessionExistsAccessCheck'
preview_link.services.yml in ./preview_link.services.yml
preview_link.services.yml
1 service uses PreviewLinkSessionExistsAccessCheck
access_check.preview_link.session_exists in ./preview_link.services.yml
Drupal\preview_link\Access\PreviewLinkSessionExistsAccessCheck

File

src/Access/PreviewLinkSessionExistsAccessCheck.php, line 16

Namespace

Drupal\preview_link\Access
View source
class PreviewLinkSessionExistsAccessCheck implements AccessInterface {

  /**
   * The session configuration.
   *
   * @var \Drupal\Core\Session\SessionConfigurationInterface
   */
  protected $sessionConfiguration;

  /**
   * Constructs a new PreviewLinkSessionExistsAccessCheck.
   *
   * @param \Drupal\Core\Session\SessionConfigurationInterface $sessionConfiguration
   *   The session configuration.
   */
  public function __construct(SessionConfigurationInterface $sessionConfiguration) {
    $this->sessionConfiguration = $sessionConfiguration;
  }

  /**
   * Checks whether the user has a session.
   *
   * @param \Symfony\Component\HttpFoundation\Request|null $request
   *   The request, if available.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   Whether the user has a session.
   */
  public function access(Request $request = NULL) : AccessResultInterface {
    return AccessResult::allowedIf($request ? $this->sessionConfiguration
      ->hasSession($request) : FALSE)
      ->addCacheContexts([
      'session.exists',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PreviewLinkSessionExistsAccessCheck::$sessionConfiguration protected property The session configuration.
PreviewLinkSessionExistsAccessCheck::access public function Checks whether the user has a session.
PreviewLinkSessionExistsAccessCheck::__construct public function Constructs a new PreviewLinkSessionExistsAccessCheck.