class IsCurrentUserPageCacheContext in Opigno dashboard 3.x
Defines a cache context for whether the URL is the current user page.
Cache context ID: 'url.path.is_current_user_page'.
Hierarchy
- class \Drupal\opigno_dashboard\Cache\Context\IsCurrentUserPageCacheContext implements CacheContextInterface
Expanded class hierarchy of IsCurrentUserPageCacheContext
1 string reference to 'IsCurrentUserPageCacheContext'
1 service uses IsCurrentUserPageCacheContext
File
- src/
Cache/ Context/ IsCurrentUserPageCacheContext.php, line 15
Namespace
Drupal\opigno_dashboard\Cache\ContextView source
class IsCurrentUserPageCacheContext implements CacheContextInterface {
/**
* If the current page is a user page.
*
* @var bool
*/
protected $isUserPage;
/**
* The current user ID.
*
* @var int
*/
protected $uid;
/**
* IsCurrentUserPageCacheContext constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The rote match service.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user account.
*/
public function __construct(RouteMatchInterface $route_match, AccountInterface $account) {
$this->uid = (int) $account
->id();
$this->isUserPage = $route_match
->getRouteName() === 'entity.user.canonical' && (int) $route_match
->getRawParameter('user') === $this->uid;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Is current user page');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return 'is_current_user_page_.' . (int) $this->isUserPage;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
$metadata = new CacheableMetadata();
$metadata
->addCacheTags([
'user:' . $this->uid,
]);
return $metadata;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IsCurrentUserPageCacheContext:: |
protected | property | If the current page is a user page. | |
IsCurrentUserPageCacheContext:: |
protected | property | The current user ID. | |
IsCurrentUserPageCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
IsCurrentUserPageCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
IsCurrentUserPageCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
IsCurrentUserPageCacheContext:: |
public | function | IsCurrentUserPageCacheContext constructor. |