The command pattern in Optimizely Content Management System (CMS) encapsulates interface actions into reusable objects, which separates logic for executing an action from concrete widgets and objects into its own testable unit.
You can add commands to a command consumer with the command pattern and its consumer and provider architecture. For example:
You want to add a command that is not dependant on a specific model to operate on, such as a plug-in to the global toolbar to open a dialog.
You want to add a command that is dependant on a model for its state, such as a command that plugs into the CMS **publishmenu** and operates on the currently selected page.
The global command registry lets you plug in commands in the system without having a reference to a specific widget instance. The global command registry maps command providers against keys so you can add a command provider that can feed a consumer with command if the global key matches.
## Plug in a command
The following example shows how to create a command provider that adds the **test **command:
The following code shows the **test **command:
This example shows how to plug into the **publishmenu** of CMS. Add the following code to your module initialzation.
## Add custom plug-in capabilities
Add the extension functionality for your own widgets with the `
epi/shell/command/\_WidgetCommandConsumerMixin mixin`. Define the property `
commandKey:` to a unique key such as `
samples.mywidgetkey`. Third-party extensions use the key to plug into your menu.