Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top