What is interceptor or plugins in Magento 2?

Question : What is interceptor or plugins in Magento 2?

Plugins (Interceptors)

Basically plugin, or interceptor both are same. it is a class only which are modifies the behavior of public class functions by intercepting a functionality and running code before, after, or around that function call. This allows you to substitute or extend the behavior of original, public methods for any class or interface.

Extensions that wish to intercept and change the behavior of a public method can create a Plugin class.

This interception approach reduces conflicts among extensions that change the behavior of the same class or method. Your Plugin class implementation changes the behavior of a class function, but it does not change the class itself. Magento calls these interceptors sequentially according to a configured sort order, so they do not conflict with one another.

Plugins can not be used on following:

Final methods
Final classes
Non-public methods
Class methods (such as static methods)
__construct
Virtual types
Objects that are instantiated before MagentoFrameworkInterception is bootstrapped

Puneet Kumar Magento Developer
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply