-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Option to enable template hints on frontend with a configurable parameter #10608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seems overcomplicated to me. Then it's easy to overlook turning this configuration off and it will go to production.
Why each developer does not use own local environment for development? Probably if we stick to |
I respectfully disagree. When a site is already live and minor frontend updates are being made it makes no sense for each developer to have their own local environment with potentially dummy date. Instead we often use a single client facing shared staging environment with near live product data. Also with the introduction of the parameter code that gives you a bit of protection if the config is left enabled. |
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
StoreManagerInterface $storeManager, | ||
DevHelper $devHelper, | ||
DebugHintsFactory $debugHintsFactory, | ||
$debugHintsPath | ||
$debugHintsPath, | ||
Http $http, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a backwards-incompatible change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. Any suggestion on how to make this backwards compatible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure. There's an example in the guides:
http://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/#ui-id-3
Even on a local environment it's a burden to go into admin in order every time you want to switch it on or off. Being able to do so using a simple GET parameter is a handy feature to have. |
* | ||
* @var string | ||
*/ | ||
protected $debugHintsShowWithParameter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current Magento Technical Vision does not recommend designing classes for inheritance, therefore please declare properties as private
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*for inheritance
I believe extensibility is still a priority, just achieved with other approaches :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Been thinking of extends
keyword. Fixed.
'showBlockHints' => $showBlockHints, | ||
]); | ||
$debugHintsParameterInUrl = $this->http->getParam('templatehints'); | ||
if ((!$debugHintsShowWithParameter) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition looks hard to read and understand, increasing possibility of an error in future refactoring. Please attempt to simplify it.
Never tried it via CLI, I'm quite used to Admin UI always opened in separate tab just because you'll need to flush caches together with switch change anyway. Would be less scary if we'd have |
Oh wow. Yeah, you should definitely try CLI, clearing caches feels much faster this way.
Yes, that makes sense. It's actually quite easy to enforce using composer (by moving relevant modules to |
For security reasons we cannot have ability for anyone to just switch on debug info on a site. If such feature is really helpful for developers, it has to be wrapped in IP whitelisting, ie only developers coming from a known, specified IP address can enable it. Then it would not even need the special parameter value, just ?showtemplatehints=1 or similar. |
@piotrekkaminski yeah, I was thinking about IP whitelisting as well together with possible filtering by xdebug session. Rejected such option as for scenario provided developers could be sitting in the same office having the same IP. |
@piotrekkaminski Okay so assuming someone leaves the option enabled and a third party discovers the parameter code and enables template hints is it any more of a risk than say for example someone running your site through magereport.com? The only serious negative I can think is that template hints would get cached and make your site look terrible/broken. @piotrekkaminski @orlangur I nested my change within isDevAllowed() so surely the option for IP whitelisting is already achieved? |
…figurable parameter #10608
@magento-team Will this be backported to 2.2? |
} | ||
if ($debugHintsWithParam && $debugHintsParameter == $debugHintsParameterInUrl) { | ||
$showHints = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overcomplicated implementation with unnecessarily high cyclomatic complexity.
Equivalent implementation:
$showHints = !$debugHintsWithParam || $debugHintsParameter == $debugHintsParameterInUrl;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote something similar to that at first and the original CI review process told me to change it. But feel free to do whatever needs to be done. I still think this is a useful feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to leave a comment in case someone stumbles upon it.
I am not part of the Magento team (not anymore) and no action is needed on your part :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature is indeed useful. Thank you so much for contributing it!
Being the original author of that code, I'm just being sensitive to increase of its complexity :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to leave a comment in case someone stumbles upon it.
How is your comment ever useful to anybody? Please provide a use case.
Thanks for paying attention to code quality though. And also let me inform you that we are accepting pull requests for more than a year already ;) This is the most natural way of constructive collaboration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to find time to learn the guidelines and submit the PR.
Until then the comment serves as a reminder to do that.
The recent addition to allow template hints to be toggled via the CLI is a step in the right direction as doing so via the admin is time consuming. However frontend development can be streamlined further with this additional feature.
Description
Within admin user is given option to enable template hints on frontend with a configurable URL parameter. So when enabled can pass ?templatehints=[parameter_value] to enable template hints providing they're enabled and the additional new option is enabled. Also for security the parameter value is configurable.
We often find ourselves in two situations
This update easily allows for this.
Fixed Issues (if relevant)
N/A
Manual testing scenarios
Contribution checklist