22
33namespace Loki \Components \Util \Controller ;
44
5+ use Loki \Components \Util \IdConvertor ;
56use Magento \Framework \Event \Manager as EventManager ;
67use Magento \Framework \View \Element \BlockInterface ;
78use 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