Skip to content

Commit b72b9fe

Browse files
committed
fix: Allow properties of ancestor block to populate child block
1 parent 46cf355 commit b72b9fe

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

ViewModel/Block/AbstractRenderer.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Loki\Base\ViewModel\Block;
44

5+
use Loki\Components\Util\Block\TransferableAncestorBlockProperties;
56
use Magento\Framework\App\State as AppState;
67
use Magento\Framework\View\Element\AbstractBlock;
78
use Magento\Framework\View\Element\Block\ArgumentInterface;
@@ -15,13 +16,24 @@ public function __construct(
1516
protected LayoutInterface $layout,
1617
protected AppState $appState,
1718
protected ChildCounter $childCounter,
19+
protected TransferableAncestorBlockProperties $transferableAncestorBlock
1820
) {
1921
}
2022

2123
public function populateBlock(
2224
AbstractBlock $block,
23-
array $data = []
25+
array $data = [],
26+
?AbstractBlock $ancestorBlock = null,
2427
): void {
28+
if ($ancestorBlock instanceof AbstractBlock) {
29+
foreach ($this->transferableAncestorBlock->getProperties() as $propertyName) {
30+
$propertyValue = $ancestorBlock->getData($propertyName);
31+
if (!empty($propertyValue)) {
32+
$block->setData($propertyName, $propertyValue);
33+
}
34+
}
35+
}
36+
2537
$block->addData($data);
2638
$block->setAncestorBlock($this->getAncestorBlock());
2739
$block->setUniqId($this->getUniqId($block, $data));

0 commit comments

Comments
 (0)