Friday, 15 November 2013

Add Custom Command

Do you need to customize one of your Sitecore Client applications with a new command for handling something new functionality? Enhancing a Sitecore Client application is straight forward and takes only the following three steps:
  • Add Custom Command item definition in the Core database
    • Create a new Chunk item
    • Create a new Custom Command item (Based on the “Small Button” template)
  • Add the Custom Command Class Code
  • Add A Custom Command definition in the Command.config file
In the case of illustrating how to create your own Custom Command, I just want to create a very simple Custom Command (called “Refresh”), which only will refresh the User Manager – nothing more and nothing less. I want to add the Custom Command into a new Chunk (called “Refresh”).

Add Custom Command Item definition in the Core database

First, navigate to the Core Database and locate the Sitecore app you want to enhance. In this case, I want to enhance the User Manager located at “/Sitecore/content/Applications/Security/User Manager“.


If you want to create a new chunk containing your custom command, navigate to the “Ribbon” definition item and create your custom chunk (based on the “/System/Ribbon/Chunk” template. In this case, I name my new chunk “Refresh”:

After creating the custom chunk (or navigated to an existing chunk) , you can create your Custom Command. Select the “/System/Ribbon/Small Button” template:


The Custom Command definition item contains seven fields. Most important is:
  • “Header”: The name of the custom command displayed in the chunk of the Sitecore application).
  • Click”: Bind your Custom Command Item definition to your Custom Command Class Code. In this case “MyCommands:Refresh”.
  • “Icon”: The icon to be displayed.

The Custom Command Class code

Now it is time for do the coding. In the case of my Refresh command I only need the following code:

Adding the Custom Command definition to Command.config

The final step is to create the custom command definition in the “/App_Config/Commands.config” file, or even better into an include file places at “/App_Config/Include/MyProject.Command.config”:

Validate The Refresh Command in the User Manager

Open your User Manager and select your Custom Command “Refresh”:


Furthermore

You can add parameters to you custom command:


In this case, Sitecore will pass the ID of the selected item to the command.

If you want to run an ASPX file as the custom application, you could do this simple by adding:


No comments: