Skip to content

Commit f19643e

Browse files
committed
Merge branch 'MC-2379' into nathan-bug-delivery
2 parents 4539025 + 5586e2b commit f19643e

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

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

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
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\NoSuchEntityException;
13+
use Magento\Cms\Model\Block as CmsBlock;
14+
815
/**
916
* Cms Static Block Widget
1017
*
11-
* @author Magento Core Team <core@magentocommerce.com>
18+
* @author Magento Core Team <core@magentocommerce.com>
1219
*/
13-
class Block extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
20+
class Block extends \Magento\Framework\View\Element\Template implements IdentityInterface
1421
{
1522
/**
1623
* @var \Magento\Cms\Model\Template\FilterProvider
@@ -31,6 +38,11 @@ class Block extends \Magento\Framework\View\Element\Template implements \Magento
3138
*/
3239
protected $_blockFactory;
3340

41+
/**
42+
* @var CmsBlock
43+
*/
44+
private $block;
45+
3446
/**
3547
* @param \Magento\Framework\View\Element\Template\Context $context
3648
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
@@ -65,19 +77,61 @@ protected function _beforeToHtml()
6577
}
6678
self::$_widgetUsageMap[$blockHash] = true;
6779

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()) {
80+
$block = $this->getBlock();
81+
82+
if ($block && $block->isActive()) {
83+
try {
84+
$storeId = $this->_storeManager->getStore()->getId();
7485
$this->setText(
7586
$this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($block->getContent())
7687
);
88+
} catch (NoSuchEntityException $e) {
7789
}
7890
}
79-
8091
unset(self::$_widgetUsageMap[$blockHash]);
8192
return $this;
8293
}
94+
95+
/**
96+
* Get identities of the Cms Block
97+
*
98+
* @return array
99+
*/
100+
public function getIdentities()
101+
{
102+
$block = $this->getBlock();
103+
104+
if ($block) {
105+
return $block->getIdentities();
106+
}
107+
108+
return [];
109+
}
110+
111+
/**
112+
* @return CmsBlock|null
113+
*/
114+
private function getBlock(): ?CmsBlock
115+
{
116+
if ($this->block) {
117+
return $this->block;
118+
}
119+
120+
$blockId = $this->getData('block_id');
121+
122+
if ($blockId) {
123+
try {
124+
$storeId = $this->_storeManager->getStore()->getId();
125+
/** @var \Magento\Cms\Model\Block $block */
126+
$block = $this->_blockFactory->create();
127+
$block->setStoreId($storeId)->load($blockId);
128+
$this->block = $block;
129+
130+
return $block;
131+
} catch (NoSuchEntityException $e) {
132+
}
133+
}
134+
135+
return null;
136+
}
83137
}

dev/tests/integration/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<!-- Semicolon-separated 'glob' patterns, that match global XML configuration files -->
5252
<const name="TESTS_GLOBAL_CONFIG_DIR" value="../../../app/etc"/>
5353
<!-- Whether to cleanup the application before running tests or not -->
54-
<const name="TESTS_CLEANUP" value="enabled"/>
54+
<const name="TESTS_CLEANUP" value="false"/>
5555
<!-- Memory usage and estimated leaks thresholds -->
5656
<!--<const name="TESTS_MEM_USAGE_LIMIT" value="1024M"/>-->
5757
<const name="TESTS_MEM_LEAK_LIMIT" value=""/>

dev/tests/integration/testsuite/Magento/Cms/Block/Widget/BlockTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ public function testToHtml()
3131
$this->assertContains('<a href="http://example.com/', $result);
3232
$this->assertContains('<p>Config value: "http://example.com/".</p>', $result);
3333
$this->assertContains('<p>Custom variable: "HTML Value".</p>', $result);
34+
$this->assertSame($cmsBlock->getIdentities(), $block->getIdentities());
3435
}
3536
}

0 commit comments

Comments
 (0)