0

I am trying to create a simple module and I can't find the propose of the attribute name and type inside the tag type and plugin in di.xml. can anyone describe attribute name used in plugin?

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="???">
        <plugin name="???" type="???" sortOrder="1"/>
    </type>
</config>

The documentation is not so clear for a beginner.

2
<config>
    <type name="{ObservedType}">
      <plugin name="{pluginName}" type="{PluginClassName}" sortOrder="1" disabled="false" />
    </type>
</config>

You must specify these elements:

  • ObservedType : A class or interface which the plugin observes.(core file path)
  • pluginName : An arbitrary plugin name that identifies a plugin. Also used to merge the configurations for the plugin.(you can set any unique name )
  • PluginClassName : The name of a plugin’s class or its virtual type. Use the following naming convention when you specify this element: \Vendor\Module\Plugin\(extension file path in which you are overriding).
0

A small explanation can be found here:

https://mage2gen.com/snippets/plugin/

Besides that you can also generate Plugins, see the following example module:

https://mage2gen.com/load/f268772e-c6b7-4b6d-83fa-b400824817d8

This example module contains the following di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin disabled="false" name="Vendor_ModuleName_Plugin_Magento_Catalog_Model_Product" sortOrder="10" type="Vendor\ModuleName\Plugin\Magento\Catalog\Model\Product"/>
    </type>
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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