magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Plugins / interception and protected methods

Open mage-eag opened this issue 11 years ago • 3 comments

The interception feature seems to be a really interesting alternative to the rewrites of M1 (especially the configuration inheritance part), but as it is not appliable to protected methods (what is understandable), is there still a solution to redefine the behaviour of protected methods ?

mage-eag avatar Dec 22 '14 10:12 mage-eag

You should understand that plugin is not functionality of rewrites. For your case you should use preference from di configuration e.g. <preference for="Some\Module\Class" type="Your\Rewrite\Class" />

Sanuch avatar Dec 22 '14 11:12 Sanuch

Ok, thanks ! (I was actually considering to use preferences, but was a bit reluctant since they are stated to be used for interfaces in the documentation)

mage-eag avatar Dec 22 '14 11:12 mage-eag

Preferences must not be used for class rewriting, as it was in M1, indeed.

is there still a solution to redefine the behaviour of protected methods ?

While technically it is possible via preferences normally you should not rely on internal class implementation and only touch public class methods.

orlangur avatar Jun 13 '18 22:06 orlangur