When I started work on pestle’s Magento 2 code generation, I deliberately left the the <preference/>
feature of Magento’s di.xml
files off the list of commands. This was, in short, to help encourage the use of plugins over preferences. i.e. to encourage developers to use the system that allowed multiple extensions to change system behavior – and not use the system that behaved like Magento 1 rewrites with a winner-take-all end result.
Unfortunately, while the plugin system shows promise, I’ve seen too many situations where it fails to provide the stable functionality a Magento developer needs. I suspect preference
s will be the order of the day in the wild, and withholding easy code generation from pestle users seems short sighted.
Configuration a class preference is easy with pestle’s magento2:generate:preference
command, just run the following (or use no arguments for interactive prompts).
$ pestle_dev magento2:generate:preference Pulsestorm_HelloWorld 'MagentoFrameworkUrl' 'PulsestormSimpleUiComponentModelUrl'
The first argument is the module you want to configure your preference in, the second is the the class or interface you’re looking to set a preference for, and the third is your new class. Pestle will add a <preference/>
node to your module’s di.xml
file, and generate a blank class file for you that automatically extends or implements the class or interface.
Upgrade instructions are in the github README file, and if you’re using the latest version before this upgrade, you should be able to use the selfupdate
command to grab the latest version.
$ pestle.phar selfupdate