44
55namespace OpenForgeProject \MageForge \Model \TemplateEngine \Decorator ;
66
7- use Magento \Framework \App \ObjectManager ;
87use Magento \Framework \Math \Random ;
98use Magento \Framework \View \Element \AbstractBlock ;
109use Magento \Framework \View \Element \BlockInterface ;
1716 */
1817class InspectorHints implements TemplateEngineInterface
1918{
20- private TemplateEngineInterface $ subject ;
21-
22- private bool $ showBlockHints ;
23-
24- private ?Random $ random = null ;
25-
2619 private string $ magentoRoot ;
2720
2821 /**
2922 * @param TemplateEngineInterface $subject
3023 * @param bool $showBlockHints
31- * @param Random|null $random
24+ * @param Random $random
3225 */
3326 public function __construct (
34- TemplateEngineInterface $ subject ,
35- bool $ showBlockHints ,
36- ? Random $ random = null
27+ private readonly TemplateEngineInterface $ subject ,
28+ private readonly bool $ showBlockHints ,
29+ private readonly Random $ random
3730 ) {
38- $ this ->subject = $ subject ;
39- $ this ->showBlockHints = $ showBlockHints ;
40- $ this ->random = $ random ?? ObjectManager::getInstance ()->get (Random::class);
41-
4231 // Get Magento root directory - try multiple strategies
4332 // 1. Try from BP constant (most reliable)
4433 if (defined ('BP ' )) {
@@ -62,6 +51,10 @@ public function render(BlockInterface $block, $templateFile, array $dictionary =
6251 {
6352 $ result = $ this ->subject ->render ($ block , $ templateFile , $ dictionary );
6453
54+ if (!$ this ->showBlockHints ) {
55+ return $ result ;
56+ }
57+
6558 // Only inject attributes if there's actual HTML content
6659 if (empty (trim ($ result ))) {
6760 return $ result ;
@@ -189,7 +182,7 @@ private function getParentBlockName(BlockInterface $block): string
189182 {
190183 if ($ block instanceof AbstractBlock) {
191184 $ parent = $ block ->getParentBlock ();
192- if ($ parent && method_exists ( $ parent , ' getNameInLayout ' ) ) {
185+ if ($ parent instanceof AbstractBlock ) {
193186 return $ parent ->getNameInLayout () ?: '' ;
194187 }
195188 }
@@ -205,7 +198,7 @@ private function getParentBlockName(BlockInterface $block): string
205198 */
206199 private function getBlockAlias (BlockInterface $ block ): string
207200 {
208- if ($ block instanceof AbstractBlock && method_exists ( $ block , ' getNameInLayout ' ) ) {
201+ if ($ block instanceof AbstractBlock) {
209202 return $ block ->getNameInLayout () ?: '' ;
210203 }
211204
0 commit comments