Skip to content

Commit d18887c

Browse files
committed
Option to enable template hints on frontend with a configurable parameter
1 parent e7d2f8f commit d18887c

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@
115115
<label>Enabled Template Path Hints for Storefront</label>
116116
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
117117
</field>
118+
<field id="template_hints_storefront_show_with_parameter" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
119+
<label>Enable Hints for Storefront with URL Parameter</label>
120+
<depends>
121+
<field id="*/*/template_hints_storefront">1</field>
122+
</depends>
123+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
124+
<comment>Use URL parameter to enable template path hints for Storefront</comment>
125+
</field>
126+
<field id="template_hints_parameter_value" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
127+
<label>Parameter Value</label>
128+
<depends>
129+
<field id="*/*/template_hints_storefront">1</field>
130+
<field id="*/*/template_hints_storefront_show_with_parameter">1</field>
131+
</depends>
132+
<comment>Add the following paramater to the URL to show template hints ?templatehints=[parameter_value]</comment>
133+
</field>
118134
<field id="template_hints_admin" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
119135
<label>Enabled Template Path Hints for Admin</label>
120136
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

app/code/Magento/Developer/Model/TemplateEngine/Plugin/DebugHints.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\View\TemplateEngineInterface;
1515
use Magento\Store\Model\ScopeInterface;
1616
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\Framework\App\Request\Http;
1718

1819
/**
1920
* Class \Magento\Developer\Model\TemplateEngine\Plugin\DebugHints
@@ -57,25 +58,52 @@ class DebugHints
5758
*/
5859
protected $debugHintsPath;
5960

61+
/**
62+
* XPath of configuration of the debug hints show with parameter
63+
*
64+
* dev/debug/template_hints_storefront_show_with_parameter
65+
*
66+
* @var string
67+
*/
68+
protected $debugHintsShowWithParameter;
69+
70+
/**
71+
* XPath of configuration of the debug hints URL parameter
72+
*
73+
* dev/debug/template_hints_parameter_value
74+
*
75+
* @var string
76+
*/
77+
protected $debugHintsParameter;
78+
6079
/**
6180
* @param ScopeConfigInterface $scopeConfig
6281
* @param StoreManagerInterface $storeManager
6382
* @param DevHelper $devHelper
6483
* @param DebugHintsFactory $debugHintsFactory
6584
* @param string $debugHintsPath
85+
* @param Http $http
86+
* @param string $debugHintsShowWithParameter
87+
* @param string $debugHintsParameter
6688
*/
6789
public function __construct(
6890
ScopeConfigInterface $scopeConfig,
6991
StoreManagerInterface $storeManager,
7092
DevHelper $devHelper,
7193
DebugHintsFactory $debugHintsFactory,
72-
$debugHintsPath
94+
$debugHintsPath,
95+
Http $http,
96+
$debugHintsShowWithParameter,
97+
$debugHintsParameter
7398
) {
7499
$this->scopeConfig = $scopeConfig;
75100
$this->storeManager = $storeManager;
76101
$this->devHelper = $devHelper;
77102
$this->debugHintsFactory = $debugHintsFactory;
78103
$this->debugHintsPath = $debugHintsPath;
104+
$this->http = $http;
105+
$this->debugHintsShowWithParameter = $debugHintsShowWithParameter;
106+
$this->debugHintsParameter = $debugHintsParameter;
79107
}
80108

81109
/**
@@ -94,15 +122,30 @@ public function afterCreate(
94122
$storeCode = $this->storeManager->getStore()->getCode();
95123
if ($this->scopeConfig->getValue($this->debugHintsPath, ScopeInterface::SCOPE_STORE, $storeCode)
96124
&& $this->devHelper->isDevAllowed()) {
97-
$showBlockHints = $this->scopeConfig->getValue(
98-
self::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS,
125+
$debugHintsShowWithParameter = $this->scopeConfig->getValue(
126+
$this->debugHintsShowWithParameter,
127+
ScopeInterface::SCOPE_STORE,
128+
$storeCode
129+
);
130+
$debugHintsParameter = $this->scopeConfig->getValue(
131+
$this->debugHintsParameter,
99132
ScopeInterface::SCOPE_STORE,
100133
$storeCode
101134
);
102-
return $this->debugHintsFactory->create([
103-
'subject' => $invocationResult,
104-
'showBlockHints' => $showBlockHints,
105-
]);
135+
$debugHintsParameterInUrl = $this->http->getParam('templatehints');
136+
if ((!$debugHintsShowWithParameter) ||
137+
($debugHintsShowWithParameter &&
138+
$debugHintsParameter == $debugHintsParameterInUrl)) {
139+
$showBlockHints = $this->scopeConfig->getValue(
140+
self::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS,
141+
ScopeInterface::SCOPE_STORE,
142+
$storeCode
143+
);
144+
return $this->debugHintsFactory->create([
145+
'subject' => $invocationResult,
146+
'showBlockHints' => $showBlockHints,
147+
]);
148+
}
106149
}
107150
return $invocationResult;
108151
}

app/code/Magento/Developer/etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
99
<default>
1010
<dev>
11+
<debug>
12+
<template_hints_storefront_show_with_parameter>0</template_hints_storefront_show_with_parameter>
13+
<template_hints_parameter_value>magento</template_hints_parameter_value>
14+
</debug>
1115
<restrict>
1216
<allow_ips />
1317
</restrict>

app/code/Magento/Developer/etc/frontend/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<type name="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints">
1313
<arguments>
1414
<argument name="debugHintsPath" xsi:type="string">dev/debug/template_hints_storefront</argument>
15+
<argument name="debugHintsShowWithParameter" xsi:type="string">dev/debug/template_hints_storefront_show_with_parameter</argument>
16+
<argument name="debugHintsParameter" xsi:type="string">dev/debug/template_hints_parameter_value</argument>
1517
</arguments>
1618
</type>
1719
</config>

0 commit comments

Comments
 (0)