14
14
use Magento \Framework \Exception \NoSuchEntityException ;
15
15
use Magento \Framework \View \Element \AbstractBlock ;
16
16
use Magento \Framework \View \Element \Context ;
17
- use Magento \Store \Api \Data \StoreInterface ;
18
17
use Magento \Store \Model \StoreManagerInterface ;
19
18
20
19
/**
@@ -83,7 +82,7 @@ protected function _toHtml(): string
83
82
private function filterOutput (string $ content ): string
84
83
{
85
84
return $ this ->filterProvider ->getBlockFilter ()
86
- ->setStoreId ($ this ->getCurrentStore ()-> getId ())
85
+ ->setStoreId ($ this ->getCurrentStoreId ())
87
86
->filter ($ content );
88
87
}
89
88
@@ -104,22 +103,22 @@ private function getCmsBlock(): BlockInterface
104
103
if (null === $ this ->cmsBlock ) {
105
104
$ this ->cmsBlock = $ this ->blockByIdentifier ->execute (
106
105
(string )$ this ->getIdentifier (),
107
- ( int ) $ this ->getCurrentStore ()-> getId ()
106
+ $ this ->getCurrentStoreId ()
108
107
);
109
108
}
110
109
111
110
return $ this ->cmsBlock ;
112
111
}
113
112
114
113
/**
115
- * Returns the StoreInterface of currently opened Store scope
114
+ * Returns the current Store ID
116
115
*
117
- * @return StoreInterface
116
+ * @return int
118
117
* @throws \Magento\Framework\Exception\NoSuchEntityException
119
118
*/
120
- private function getCurrentStore (): StoreInterface
119
+ private function getCurrentStoreId (): int
121
120
{
122
- return $ this ->storeManager ->getStore ();
121
+ return ( int ) $ this ->storeManager ->getStore ()-> getId ();
123
122
}
124
123
125
124
/**
@@ -133,10 +132,19 @@ private function getCurrentStore(): StoreInterface
133
132
public function getIdentities (): array
134
133
{
135
134
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 ;
140
148
} catch (NoSuchEntityException $ e ) {
141
149
// If CMS Block does not exist, it should not be cached
142
150
return [];
0 commit comments