You are here

class UserHelpTabAccess in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_authentication/src/Access/UserHelpTabAccess.php \Drupal\ldap_authentication\Access\UserHelpTabAccess

Checks whether the use is allowed to see the help tab.

Hierarchy

Expanded class hierarchy of UserHelpTabAccess

1 string reference to 'UserHelpTabAccess'
ldap_authentication.services.yml in ldap_authentication/ldap_authentication.services.yml
ldap_authentication/ldap_authentication.services.yml
1 service uses UserHelpTabAccess
ldap_authentication.user_help_tab_access in ldap_authentication/ldap_authentication.services.yml
Drupal\ldap_authentication\Access\UserHelpTabAccess

File

ldap_authentication/src/Access/UserHelpTabAccess.php, line 14

Namespace

Drupal\ldap_authentication\Access
View source
class UserHelpTabAccess implements AccessInterface {
  private $config;
  private $currentUser;

  /**
   * Constructor.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
    $this->config = $config_factory
      ->get('ldap_authentication.settings');
    $this->currentUser = $current_user;
  }

  /**
   * Access callback for help tab.
   *
   * @return bool
   *   Whether user is allowed to see tab or not.
   */
  public function accessLdapHelpTab() {
    $mode = $this->config
      ->get('authenticationMode');
    if ($mode == LdapAuthenticationConfiguration::MODE_MIXED) {
      if (ldap_authentication_ldap_authenticated($this->currentUser)) {
        return TRUE;
      }
    }
    elseif ($mode == LdapAuthenticationConfiguration::MODE_EXCLUSIVE) {
      if ($this->currentUser
        ->isAnonymous() || ldap_authentication_ldap_authenticated($this->currentUser)) {
        return TRUE;
      }
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function access(AccountInterface $account) {
    if ($this
      ->accessLdapHelpTab()) {
      return AccessResultAllowed::allowed();
    }
    else {
      return AccessResultAllowed::forbidden();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserHelpTabAccess::$config private property
UserHelpTabAccess::$currentUser private property
UserHelpTabAccess::access public function
UserHelpTabAccess::accessLdapHelpTab public function Access callback for help tab.
UserHelpTabAccess::__construct public function Constructor.