Skip to content
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

Magento2.Templates.HelperInTemplate Rule #121

Closed
diazwatson opened this issue Aug 1, 2019 · 0 comments
Closed

Magento2.Templates.HelperInTemplate Rule #121

diazwatson opened this issue Aug 1, 2019 · 0 comments
Labels
accepted New rule is accepted proposal New rule proposal
Projects

Comments

@diazwatson
Copy link
Contributor

diazwatson commented Aug 1, 2019

After the work done in #108 I kept wondering:

  • Why we include this rule in ThisInTemplateSniff?
  • Why not create a separate HelperInTemplateSniff to check for the use of helpers in PHTML files?
  • Should we also explain how to create a ViewModel or is enough mentioning how to use it in the template?
  • How about adding a link to the DevDocs to explain how to create the viewModel?

This is a proposal to answer those questions.

Rule

The use of helpers is in general discouraged. For PHTML, consider using ViewModel instead.

Reason

The use of helpers is in general discouraged therefore any $this->helper(<helper_class>) code used in PHTML templates should be refactored. Consider using ViewModel instead.

Implementation

Typical example of a helper being used in a PHTML:

<?php $_incl = $block->helper(<helper_class>)->...; ?>

Once the ViewModel is created, call it in the PHTML as follow:

<?php $viewModel = $block->getViewModel(); ?>

or

<?php $viewModel = $block->getData('viewModel'); ?>
@diazwatson diazwatson added the proposal New rule proposal label Aug 1, 2019
@m2-community-project m2-community-project bot added this to Ready for Grooming in Backlog Aug 1, 2019
@diazwatson diazwatson self-assigned this Aug 1, 2019
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Backlog Aug 1, 2019
diazwatson added a commit to diazwatson/magento-coding-standard that referenced this issue Aug 1, 2019
@m2-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in Backlog Aug 1, 2019
diazwatson added a commit to diazwatson/magento-coding-standard that referenced this issue Aug 10, 2019
@lenaorobei lenaorobei added the accepted New rule is accepted label Aug 12, 2019
diazwatson added a commit to diazwatson/magento-coding-standard that referenced this issue Aug 12, 2019
diazwatson added a commit to diazwatson/magento-coding-standard that referenced this issue Aug 15, 2019
lenaorobei added a commit to diazwatson/magento-coding-standard that referenced this issue Aug 16, 2019
lenaorobei added a commit that referenced this issue Aug 16, 2019
#121 Magento2.Templates.HelperInTemplate Rule porposal
@okorshenko okorshenko moved this from Pull Request In Progress to Done in Backlog May 14, 2020
magento-devops-reposync-svc pushed a commit that referenced this issue Nov 15, 2021
…heck-array-autovivification-fix

Fixed code array autovivification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted New rule is accepted proposal New rule proposal
Projects
Backlog
  
Done
Development

No branches or pull requests

2 participants