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

Add $data array as property to Magento\Backend\App\Action\Plugin\Authentication #20152

Closed
wants to merge 2 commits into
base: 2.3-develop
from

Conversation

Projects
None yet
4 participants
@nickolasburr
Copy link

nickolasburr commented Jan 9, 2019

Description (*)

Add $data array property to Magento\Backend\App\Action\Plugin\Authentication. This makes it easier to use DI to extend the class.

Fixed Issues (if relevant)

  1. N/A

Manual testing scenarios (*)

  1. Create basic module with class that extends Magento\Backend\App\Action\Plugin\Authentication
  2. Add output method to subclass, which will var_dump the $data array
  3. Add subclass <preference> in etc/di.xml
  4. Add subclass <type> with arbitrary arguments given to $data in etc/di.xml
  5. Call output method to display the given DI arguments

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)

nickolasburr added some commits Jan 9, 2019

Add $data array as property
Add $data array as property to Magento\Backend\App\Action\Plugin\Authentication
@magento-cicd2

This comment has been minimized.

Copy link
Contributor

magento-cicd2 commented Jan 9, 2019

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team

This comment has been minimized.

Copy link
Contributor

magento-engcom-team commented Jan 9, 2019

Hi @nickolasburr. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@kandy

This comment has been minimized.

Copy link
Contributor

kandy commented Jan 9, 2019

Your change doesn't make any sense for me. Can you explain what you try to achieve?
Also, pay attention that we do not recommend to extend core classes

@nickolasburr

This comment has been minimized.

Copy link

nickolasburr commented Jan 9, 2019

In certain situations where you may need to change the mode of authentication for an admin user, it is necessary to override this class. The proposed change is to allow overriding this class without having to also override the constructor by allowing the passing of arbitrary data via the $data property.

@kandy

This comment has been minimized.

Copy link
Contributor

kandy commented Jan 9, 2019

But why you do not want to override constructor?

@kandy kandy closed this Jan 9, 2019

@contribution-survey

This comment has been minimized.

Copy link

contribution-survey bot commented Jan 9, 2019

Hi @nickolasburr, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@nickolasburr

This comment has been minimized.

Copy link

nickolasburr commented Jan 9, 2019

Overriding the constructor unnecessarily requires additional overhead code, and makes the inheritance brittle and susceptible to breakage. Constructor method signatures change frequently in Magento, and the proposed changes provide two key benefits (especially for extension developers):

  1. Allow arguments to be given via di.xml, making it more manageable to extend the class
  2. Prevent subclasses of Magento\Backend\App\Action\Plugin\Authentication from breaking if there's a backward-incompatible change made in a future release

There are several examples of this done elsewhere in Magento, such as:

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Tax/Model/Calculation.php#L232
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Shipping/Model/Order/Track.php#L54
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Shipping/Model/Order/Pdf/Packaging.php#L71

Albeit, each of these classes inherit from Magento\Framework\DataObject. If that's a more desirable approach, I'm more than happy to make the change and send another pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment