Skip to content

Commit 73fb7e8

Browse files
committed
MC-2379: CMS content containing widget directives is not updated when the linked widget directive entities are updated
- Implemented IdentityInterface for widget block model
1 parent a04f913 commit 73fb7e8

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

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

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Cms\Block\Widget;
710

11+
use Magento\Framework\DataObject\IdentityInterface;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Widget\Block\BlockInterface;
15+
use Magento\Cms\Model\Block as CmsBlock;
16+
817
/**
918
* Cms Static Block Widget
1019
*
11-
* @author Magento Core Team <core@magentocommerce.com>
20+
* @author Magento Core Team <core@magentocommerce.com>
1221
*/
13-
class Block extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
22+
class Block extends \Magento\Framework\View\Element\Template implements BlockInterface, IdentityInterface
1423
{
1524
/**
1625
* @var \Magento\Cms\Model\Template\FilterProvider
@@ -31,6 +40,11 @@ class Block extends \Magento\Framework\View\Element\Template implements \Magento
3140
*/
3241
protected $_blockFactory;
3342

43+
/**
44+
* @var CmsBlock
45+
*/
46+
private $block;
47+
3448
/**
3549
* @param \Magento\Framework\View\Element\Template\Context $context
3650
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
@@ -65,19 +79,61 @@ protected function _beforeToHtml()
6579
}
6680
self::$_widgetUsageMap[$blockHash] = true;
6781

68-
if ($blockId) {
69-
$storeId = $this->_storeManager->getStore()->getId();
70-
/** @var \Magento\Cms\Model\Block $block */
71-
$block = $this->_blockFactory->create();
72-
$block->setStoreId($storeId)->load($blockId);
73-
if ($block->isActive()) {
82+
$block = $this->getBlock();
83+
84+
if ($block && $block->isActive()) {
85+
try {
86+
$storeId = $this->_storeManager->getStore()->getId();
7487
$this->setText(
7588
$this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($block->getContent())
7689
);
90+
} catch (NoSuchEntityException $e) {
7791
}
7892
}
79-
8093
unset(self::$_widgetUsageMap[$blockHash]);
8194
return $this;
8295
}
96+
97+
/**
98+
* Get identities of the Cms Block
99+
*
100+
* @return array
101+
*/
102+
public function getIdentities()
103+
{
104+
$block = $this->getBlock();
105+
106+
if ($block) {
107+
return $block->getIdentities();
108+
}
109+
110+
return [];
111+
}
112+
113+
/**
114+
* @return CmsBlock|null
115+
*/
116+
private function getBlock(): ?CmsBlock
117+
{
118+
if ($this->block) {
119+
return $this->block;
120+
}
121+
122+
$blockId = $this->getData('block_id');
123+
124+
if ($blockId) {
125+
try {
126+
$storeId = $this->_storeManager->getStore()->getId();
127+
/** @var \Magento\Cms\Model\Block $block */
128+
$block = $this->_blockFactory->create();
129+
$block->setStoreId($storeId)->load($blockId);
130+
$this->block = $block;
131+
132+
return $block;
133+
} catch (NoSuchEntityException $e) {
134+
}
135+
}
136+
137+
return null;
138+
}
83139
}

0 commit comments

Comments
 (0)