14

Are there any consequences for using a plugin class in Magento 2 that doesn't end in \Plugin? The docs suggest that this class should end in the name \Plugin.

The name of a plug-in’s class or its virtual type. Use the following schema when you specify this element: \Plugin.

However, there's several code plugins that don't follow this.

<!-- #File: app/code/Magento/Weee/etc/frontend/di.xml-->
<plugin name="weee-app-action-dispatchController-context-plugin"
        type="Magento\Weee\Model\App\Action\ContextPlugin"/>

Are there any programmatic consequences to not using \Plugin in your class name? Or is this just a convention -- similar to Magento 1's _Observer class name convention?

2 Answers 2

5

So the official training slides/instruction say "The name of a plugin class or its virtual type; uses the naming convention \Plugin.". However, the solutions guide for the exercises creates a plugin without following that convention. So unless something has changed architecturally, I would say this is just a convention

3

In magento-2 ,The usage of plugin name in the classname is just a convention and is not mandatory as we use the observer class name.

The following is generalized syntax code of plugin :

<plugin name="plugin_name" type="class_name" />

where the type just holds the class name which needs to be instantiated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.