diff --git a/guides/v2.2/extension-dev-guide/plugins.md b/guides/v2.2/extension-dev-guide/plugins.md index a60ce6fb27e..30790f81885 100644 --- a/guides/v2.2/extension-dev-guide/plugins.md +++ b/guides/v2.2/extension-dev-guide/plugins.md @@ -57,6 +57,44 @@ By applying code before, after, or around a public method, a plugin extends or m The first argument for the before, after, and around methods is an object that provides access to all public methods of the observed method's class. +### Plugin method naming convention + +It is a Magento best practice to capitalize the first letter of the class method name for which you want to create a plugin before adding `before`, `around` or `after` prefixes to it. + +For example, to create a plugin for the `setName` method of some class: + +```php +... + public function setName($name) + { + ... + } +... +``` + +In the plugin class, the `setName` method may have one of the following names: +- `beforeSetName` +- `aroundSetName` +- `afterSetName` + +If the first letter in the name of the class method name for which you want to create a plugin is the `underscore` character, then you do not need to capitalize it in the plugin class. + +For example, to create a plugin for the `_construct` method of some class: + +```php +... + public function _construct() + { + ... + } +... +``` + +Use the following method names for the `_construct` method in the plugin class: +- `before_construct` +- `around_construct` +- `after_construct` + #### Before methods Magento runs all before methods ahead of the call to an observed method. These methods must have the same name as the observed method with 'before' as the prefix.