Skip to content

Commit 2e385e1

Browse files
committed
Merge remote-tracking branch 'trigger/nathan-bug-delivery' into bug_fixes_beta_bugs
2 parents e0cf3f7 + 46a9884 commit 2e385e1

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

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

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
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+
use Magento\Widget\Block\BlockInterface;
15+
816
/**
917
* Cms Static Block Widget
1018
*
11-
* @author Magento Core Team <[email protected]>
19+
* @author Magento Core Team <[email protected]>
1220
*/
13-
class Block extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
21+
class Block extends \Magento\Framework\View\Element\Template implements BlockInterface, IdentityInterface
1422
{
1523
/**
1624
* @var \Magento\Cms\Model\Template\FilterProvider
@@ -31,6 +39,11 @@ class Block extends \Magento\Framework\View\Element\Template implements \Magento
3139
*/
3240
protected $_blockFactory;
3341

42+
/**
43+
* @var CmsBlock
44+
*/
45+
private $block;
46+
3447
/**
3548
* @param \Magento\Framework\View\Element\Template\Context $context
3649
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
@@ -49,8 +62,9 @@ public function __construct(
4962
}
5063

5164
/**
52-
* Prepare block text and determine whether block output enabled or not
53-
* Prevent blocks recursion if needed
65+
* Prepare block text and determine whether block output enabled or not.
66+
*
67+
* Prevent blocks recursion if needed.
5468
*
5569
* @return $this
5670
*/
@@ -65,19 +79,63 @@ 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+
* Get block
115+
*
116+
* @return CmsBlock|null
117+
*/
118+
private function getBlock(): ?CmsBlock
119+
{
120+
if ($this->block) {
121+
return $this->block;
122+
}
123+
124+
$blockId = $this->getData('block_id');
125+
126+
if ($blockId) {
127+
try {
128+
$storeId = $this->_storeManager->getStore()->getId();
129+
/** @var \Magento\Cms\Model\Block $block */
130+
$block = $this->_blockFactory->create();
131+
$block->setStoreId($storeId)->load($blockId);
132+
$this->block = $block;
133+
134+
return $block;
135+
} catch (NoSuchEntityException $e) {
136+
}
137+
}
138+
139+
return null;
140+
}
83141
}

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
}

dev/tests/static/framework/Magento/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
<rule ref="PSR2"/>
1212

13+
<rule ref="PSR2.Files.ClosingTag">
14+
<exclude-pattern>*.phtml</exclude-pattern>
15+
</rule>
16+
1317
<rule ref="Magento.Files.LineLength">
1418
<properties>
1519
<property name="lineLimit" value="120"/>

0 commit comments

Comments
 (0)