Skip to content

Commit 3477582

Browse files
committed
Allow target to be any block, not just components
1 parent a4f919b commit 3477582

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Util/Controller/TargetRenderer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Loki\Components\Util\Controller;
44

5+
use Loki\Components\Util\IdConvertor;
56
use Magento\Framework\Event\Manager as EventManager;
67
use Magento\Framework\View\Element\BlockInterface;
78
use Magento\Framework\View\LayoutInterface;
@@ -11,7 +12,8 @@ class TargetRenderer
1112
{
1213
public function __construct(
1314
private readonly EventManager $eventManager,
14-
private readonly ComponentRegistry $componentRegistry,
15+
private readonly LayoutInterface $layout,
16+
private readonly IdConvertor $idConvertor,
1517
) {
1618
}
1719

@@ -44,9 +46,21 @@ private function getTargetBlockNames(array $targets): array
4446

4547
private function convertTargetsToBlockNames(array $targets): array
4648
{
49+
$allBlockNames = array_keys($this->layout->getAllBlocks());
50+
4751
$blockNames = [];
4852
foreach ($targets as $target) {
49-
$blockNames[] = $this->componentRegistry->getBlockNameFromElementId($target);
53+
if (in_array($target, $allBlockNames, true)) {
54+
$blockNames[] = $target;
55+
continue;
56+
}
57+
58+
foreach ($allBlockNames as $blockName) {
59+
$elementId = $this->idConvertor->toElementId($blockName);
60+
if ($elementId === $target) {
61+
$blockNames[] = $blockName;
62+
}
63+
}
5064
}
5165

5266
return $blockNames;

0 commit comments

Comments
 (0)