class WishlistCacheContext in Commerce Wishlist 8.3
Defines the WishlistCacheContext service, for "per wishlist" caching.
Cache context ID: 'wishlist'.
Hierarchy
- class \Drupal\commerce_wishlist\Cache\Context\WishlistCacheContext implements CacheContextInterface
Expanded class hierarchy of WishlistCacheContext
1 file declares its use of WishlistCacheContext
- WishlistCacheContextTest.php in tests/
src/ Unit/ WishlistCacheContextTest.php
1 string reference to 'WishlistCacheContext'
1 service uses WishlistCacheContext
File
- src/
Cache/ Context/ WishlistCacheContext.php, line 15
Namespace
Drupal\commerce_wishlist\Cache\ContextView source
class WishlistCacheContext implements CacheContextInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The wishlist provider service.
*
* @var \Drupal\commerce_wishlist\WishlistProviderInterface
*/
protected $wishlistProvider;
/**
* Constructs a new WishlistCacheContext object.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user account.
* @param \Drupal\commerce_wishlist\WishlistProviderInterface $wishlist_provider
* The wishlist provider service.
*/
public function __construct(AccountInterface $account, WishlistProviderInterface $wishlist_provider) {
$this->account = $account;
$this->wishlistProvider = $wishlist_provider;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Current wishlist IDs');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return implode(':', $this->wishlistProvider
->getWishlistIds($this->account));
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
$metadata = new CacheableMetadata();
foreach ($this->wishlistProvider
->getWishlists($this->account) as $wishlist) {
$metadata
->addCacheableDependency($wishlist);
}
return $metadata;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WishlistCacheContext:: |
protected | property | The current user. | |
WishlistCacheContext:: |
protected | property | The wishlist provider service. | |
WishlistCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
WishlistCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
WishlistCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
WishlistCacheContext:: |
public | function | Constructs a new WishlistCacheContext object. |