You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Never Extend from Magento\Framework\App\Helper\AbstractHelper
Reason
The AbstractHelper has many dependy that you never need for your helper implementation.
Also it breacks your helper if you use the ScopeConfigInterface and upgrade 2.1 to 2.2.
Implementation
The text was updated successfully, but these errors were encountered:
there is one limitation if you do not extend it (although I totally agree with you, best case do not use helpers at all anymore).
\Magento\Framework\View\TemplateEngine\Php::helper($className) throws an Exception if it is not extended from AbstractHelper.
Before view models have been introduced this function could save a lot of time in some cases. I'm not proud of it but we might still have 1 or 2 of them in older code.
True. I would rather say that a helper should not exist at all or that the constructor should not be overridden. You could define a helper that only extends from the parent, just for the sake of using the helper in PHTML templates. But extending the constructor of a helper-that-inherits-from-parent leads to the mess that @larsroettig describes. So maybe we flag it if it does NOT match the following:
A helper class that does not extend from any other class.
A helper class that extends a parent but does not override the constructor.
And the notes can tell anyway that helpers are deprecated and it is better to create a specific class per set of helper-methods.
Rule
Never Extend from Magento\Framework\App\Helper\AbstractHelper
Reason
The AbstractHelper has many dependy that you never need for your helper implementation.
Also it breacks your helper if you use the ScopeConfigInterface and upgrade 2.1 to 2.2.
Implementation
The text was updated successfully, but these errors were encountered: