class CommerceLocalStockTransactionSubscriber in Commerce Stock 8
Test class to test the commerce_stock transaction events.
Hierarchy
- class \Drupal\commerce_stock_local\EventSubscriber\CommerceLocalStockTransactionSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of CommerceLocalStockTransactionSubscriber
1 string reference to 'CommerceLocalStockTransactionSubscriber'
- commerce_stock_local.services.yml in modules/
local_storage/ commerce_stock_local.services.yml - modules/local_storage/commerce_stock_local.services.yml
1 service uses CommerceLocalStockTransactionSubscriber
File
- modules/
local_storage/ src/ EventSubscriber/ CommerceLocalStockTransactionSubscriber.php, line 13
Namespace
Drupal\commerce_stock_local\EventSubscriberView source
class CommerceLocalStockTransactionSubscriber implements EventSubscriberInterface {
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* Constructs a CommerceStockTransactionSubscriber.
*
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
*/
public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
$this->cacheTagsInvalidator = $cache_tags_invalidator;
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents() {
return [
LocalStockTransactionEvents::LOCAL_STOCK_TRANSACTION_INSERT => 'onTransactionInsert',
];
}
/**
* Invalidate the cache for the purchased entity.
*
* @param \Drupal\commerce_stock_local\Event\LocalStockTransactionEvent $event
* The event.
*/
public function onTransactionInsert(LocalStockTransactionEvent $event) {
$purchasableEntity = $event
->getEntity();
$this->cacheTagsInvalidator
->invalidateTags($purchasableEntity
->getCacheTagsToInvalidate());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceLocalStockTransactionSubscriber:: |
protected | property | The cache tags invalidator. | |
CommerceLocalStockTransactionSubscriber:: |
public static | function | @inheritDoc | |
CommerceLocalStockTransactionSubscriber:: |
public | function | Invalidate the cache for the purchased entity. | |
CommerceLocalStockTransactionSubscriber:: |
public | function | Constructs a CommerceStockTransactionSubscriber. |