Skip to content

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

Merged
merged 4 commits into from
Aug 28, 2017
Merged

Option to enable template hints on frontend with a configurable parameter #10608

merged 4 commits into from
Aug 28, 2017

Conversation

DominicWatts
Copy link
Contributor

@DominicWatts DominicWatts commented Aug 21, 2017

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

  • Dev 1 working on site wants template hints enabled, Dev 2 doesn't
  • Dev 1 on 1 screen wants template hints, on Dev 1 on screen 2 doesn't

This update easily allows for this.

Fixed Issues (if relevant)

N/A

Manual testing scenarios

  1. Within Magento backend under Advanced | Developer
  2. Enabled Template Path Hints for Storefront - Yes
  3. Enable Hints for Storefront with URL Parameter - Yes
  4. Configure Parameter Value - magento
  5. On frontend Storeview enable template hints with parameter ?templatehints=magento

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@orlangur
Copy link
Contributor

Seems overcomplicated to me. Then it's easy to overlook turning this configuration off and it will go to production.

We often find ourselves in two situations

Why each developer does not use own local environment for development?

Probably if we stick to xdebug_session cookie or something it could become something worth merging.

@XigenDominic
Copy link

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.

@ishakhsuvarov ishakhsuvarov added this to the August 2017 milestone Aug 22, 2017
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
DevHelper $devHelper,
DebugHintsFactory $debugHintsFactory,
$debugHintsPath
$debugHintsPath,
Http $http,
Copy link
Contributor

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@korostii
Copy link
Contributor

Why each developer does not use own local environment for development?

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;
Copy link
Contributor

@ishakhsuvarov ishakhsuvarov Aug 22, 2017

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.

Copy link
Contributor

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 :)

Copy link
Contributor

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) ||
Copy link
Contributor

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.

@orlangur
Copy link
Contributor

@korostii,

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.

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 Magento_Developer module disabled by design when deployed to production or something like that.

@korostii
Copy link
Contributor

I'm quite used to Admin UI always opened in separate tab just because you'll need to flush caches

Oh wow. Yeah, you should definitely try CLI, clearing caches feels much faster this way.

Would be less scary if we'd have Magento_Developer module disabled by design when deployed to production or something like that.

Yes, that makes sense. It's actually quite easy to enforce using composer (by moving relevant modules to require-dev section, see also #8971, #5262 ). Oh, and you'll also need to have the config.php added to .gitignore in order to have different sets of enabled modules between instances.
However there might still be some internal dependencies you'd need to untangle additionally, of course.

@piotrekkaminski
Copy link
Contributor

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.

@orlangur
Copy link
Contributor

@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.

@XigenDominic
Copy link

@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?

@ishakhsuvarov ishakhsuvarov self-assigned this Aug 23, 2017
@magento-team magento-team merged commit d143e5d into magento:develop Aug 28, 2017
magento-team pushed a commit that referenced this pull request Aug 28, 2017
@Ctucker9233
Copy link

@magento-team Will this be backported to 2.2?

}
if ($debugHintsWithParam && $debugHintsParameter == $debugHintsParameterInUrl) {
$showHints = true;
}
Copy link

@sshymko sshymko Mar 20, 2019

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;

Copy link
Contributor Author

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.

Copy link

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 :)

Copy link

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sshymko,

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.

Copy link

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.

@ghost ghost assigned orlangur Mar 20, 2019
@orlangur orlangur removed their assignment Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants