You are here

class UserEmailVerificationNeeded in User email verification 8

Defines the UserEmailVerificationNeeded context service.

Cache context ID: 'user_email_verification_needed'.

Hierarchy

Expanded class hierarchy of UserEmailVerificationNeeded

1 string reference to 'UserEmailVerificationNeeded'
user_email_verification.services.yml in ./user_email_verification.services.yml
user_email_verification.services.yml
1 service uses UserEmailVerificationNeeded
cache_context.user_email_verification_needed in ./user_email_verification.services.yml
Drupal\user_email_verification\Cache\Context\UserEmailVerificationNeeded

File

src/Cache/Context/UserEmailVerificationNeeded.php, line 15

Namespace

Drupal\user_email_verification\Cache\Context
View source
class UserEmailVerificationNeeded implements CacheContextInterface {

  /**
   * User email verification helper service.
   *
   * @var \Drupal\user_email_verification\UserEmailVerificationInterface
   */
  protected $userEmailVerification;

  /**
   * The current active user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * Constructs a new object.
   *
   * @param \Drupal\user_email_verification\UserEmailVerificationInterface $user_email_verification_service
   *   User email verification helper service.
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   *   The current active user.
   */
  public function __construct(UserEmailVerificationInterface $user_email_verification_service, AccountProxyInterface $current_user) {
    $this->userEmailVerification = $user_email_verification_service;
    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('User Email verification needed');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->currentUser
      ->isAuthenticated() && $this->userEmailVerification
      ->isVerificationNeeded() ? 'uev-needed' : '';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($type = NULL) {
    $cacheability = new CacheableMetadata();
    $cacheability
      ->addCacheContexts([
      'user',
    ]);
    return $cacheability;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserEmailVerificationNeeded::$currentUser protected property The current active user.
UserEmailVerificationNeeded::$userEmailVerification protected property User email verification helper service.
UserEmailVerificationNeeded::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
UserEmailVerificationNeeded::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
UserEmailVerificationNeeded::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
UserEmailVerificationNeeded::__construct public function Constructs a new object.