You are here

class UserHelpTabAccess in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 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 16

Namespace

Drupal\ldap_authentication\Access
View source
class UserHelpTabAccess implements AccessInterface {

  /**
   * Config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * Current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * Externalauth.
   *
   * @var \Drupal\externalauth\Authmap
   */
  protected $externalAuth;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   Config Factory.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user.
   * @param \Drupal\externalauth\Authmap $external_auth
   *   External auth.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user, Authmap $external_auth) {
    $this->config = $config_factory
      ->get('ldap_authentication.settings');
    $this->currentUser = $current_user;
    $this->externalAuth = $external_auth;
  }

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
UserHelpTabAccess::$config protected property Config.
UserHelpTabAccess::$currentUser protected property Current user.
UserHelpTabAccess::$externalAuth protected property Externalauth.
UserHelpTabAccess::access public function
UserHelpTabAccess::accessLdapHelpTab public function Access callback for help tab.
UserHelpTabAccess::__construct public function Constructor.