You are here

class RegistrationLinkAccessCheck in Registration Link 8.2

Access check for user registration routes.

@package Drupal\registration_link\Access

Hierarchy

Expanded class hierarchy of RegistrationLinkAccessCheck

1 string reference to 'RegistrationLinkAccessCheck'
registration_link.services.yml in ./registration_link.services.yml
registration_link.services.yml
1 service uses RegistrationLinkAccessCheck
registration_link.registration_link_custom_access in ./registration_link.services.yml
Drupal\registration_link\Access\RegistrationLinkAccessCheck

File

src/Access/RegistrationLinkAccessCheck.php, line 16

Namespace

Drupal\registration_link\Access
View source
class RegistrationLinkAccessCheck implements AccessInterface {

  /**
   * The Config Factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * RegistrationLinkAccessCheck constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactory $configFactory
   *   The Config Factory service.
   */
  public function __construct(ConfigFactory $configFactory) {
    $this->configFactory = $configFactory
      ->get('user.settings');
  }

  /**
   * Checks access.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return $this|\Drupal\Core\Access\AccessResultAllowed
   *   The access result.
   */
  public function access(AccountInterface $account) {
    if (in_array('administrator', $account
      ->getRoles())) {
      return AccessResult::allowed();
    }
    return AccessResult::allowedIf($account
      ->isAnonymous() && $this->configFactory
      ->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY)
      ->addCacheableDependency($this->configFactory);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegistrationLinkAccessCheck::$configFactory protected property The Config Factory service.
RegistrationLinkAccessCheck::access public function Checks access.
RegistrationLinkAccessCheck::__construct public function RegistrationLinkAccessCheck constructor.