Skip to content

Commit 4501271

Browse files
committed
Add support for save Block in the caches for all scopes that block is assigned to
1 parent a100d24 commit 4501271

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

app/code/Magento/Cms/Block/BlockByIdentifier.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Framework\Exception\NoSuchEntityException;
1515
use Magento\Framework\View\Element\AbstractBlock;
1616
use Magento\Framework\View\Element\Context;
17-
use Magento\Store\Api\Data\StoreInterface;
1817
use Magento\Store\Model\StoreManagerInterface;
1918

2019
/**
@@ -83,7 +82,7 @@ protected function _toHtml(): string
8382
private function filterOutput(string $content): string
8483
{
8584
return $this->filterProvider->getBlockFilter()
86-
->setStoreId($this->getCurrentStore()->getId())
85+
->setStoreId($this->getCurrentStoreId())
8786
->filter($content);
8887
}
8988

@@ -104,22 +103,22 @@ private function getCmsBlock(): BlockInterface
104103
if (null === $this->cmsBlock) {
105104
$this->cmsBlock = $this->blockByIdentifier->execute(
106105
(string)$this->getIdentifier(),
107-
(int)$this->getCurrentStore()->getId()
106+
$this->getCurrentStoreId()
108107
);
109108
}
110109

111110
return $this->cmsBlock;
112111
}
113112

114113
/**
115-
* Returns the StoreInterface of currently opened Store scope
114+
* Returns the current Store ID
116115
*
117-
* @return StoreInterface
116+
* @return int
118117
* @throws \Magento\Framework\Exception\NoSuchEntityException
119118
*/
120-
private function getCurrentStore(): StoreInterface
119+
private function getCurrentStoreId(): int
121120
{
122-
return $this->storeManager->getStore();
121+
return (int)$this->storeManager->getStore()->getId();
123122
}
124123

125124
/**
@@ -133,10 +132,19 @@ private function getCurrentStore(): StoreInterface
133132
public function getIdentities(): array
134133
{
135134
try {
136-
return [
137-
self::CACHE_KEY_PREFIX . '_' . $this->getCmsBlock()->getId(),
138-
self::CACHE_KEY_PREFIX . '_' . $this->getIdentifier() . '_' . $this->getCurrentStore()->getId()
139-
];
135+
$cmsBlock = $this->getCmsBlock();
136+
137+
$identities = [self::CACHE_KEY_PREFIX . '_' . $cmsBlock->getId()];
138+
139+
if (method_exists($this->getCmsBlock(), 'getStores')) {
140+
foreach ($cmsBlock->getStores() as $store) {
141+
$identities[] = self::CACHE_KEY_PREFIX . '_' . $this->getIdentifier() . '_' . $store;
142+
}
143+
}
144+
145+
$identities[] = self::CACHE_KEY_PREFIX . '_' . $this->getIdentifier() . '_' . $this->getCurrentStoreId();
146+
147+
return $identities;
140148
} catch (NoSuchEntityException $e) {
141149
// If CMS Block does not exist, it should not be cached
142150
return [];

0 commit comments

Comments
 (0)