Add a Command to the Sitecore Item Context Menu

The current version of this blog post is at:

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Add-a-Command-to-the-Sitecore-Item-Context-Menu.aspx

During my dreamcore 2010 presentation, “Ten Things You Didn’t Know You Could Do with Sitecore”, I showed an item context menu to copy the full path of the selected item to the Windows clipboard. I explained that I had coped this feature from the Path command in the Show group on the Developer tab. You can register any number of commands on the default item context menu with the Sitecore ASP.NET CMS. It’s easiest to use commands that already exist, but you can use existing commands as well. For a little more information about commands, see my previous blog post Sitecore Ribbon Command to Debug Any Item in Any Database.

The Core database contains the ribbon definition. Each command contains a token that maps to a class through the /App_Config/commands.config file. The /Sitecore/Content/Applications/Content Editor/Ribbons/Chunks/Show/Path item in the Core database defines the Path command in the Show group on the Developer tab. Note the values of the Click and Icon fields in the /Sitecore/Content/Applications/Content Editor/Ribbons/Chunks/Show/Path item:

Click: clipboard:copypathtoclipboard

Icon: applications/16×16/window_dialog.png

To create an item context menu to copy the path of the selected item to the Windows clipboard, under the /Sitecore/Content/Applications/Content Editor/Context Menues/Default item in the Core database, insert an item named Copy Path using the System/Menus/Menu item data template. I usually just duplicate one of the existing items and then update its properties. Sort the Copy Path context menu after the Duplicate entry. Set the Display name field to Copy Path. Set Icon to the value copied from the Icon field of the /Sitecore/Content/Applications/Content Editor/Ribbons/Chunks/Show/Path item:

applications/16×16/window_dialog.png

You can set access rights on the definition item to control who can use the command, or you can override the class specified in the /App_Config/commands.config file for the /configuration/command element named clipboard:copypathtoclipboard.

Context menu commands differ from ribbon commands because the user can right-click an item other than the item selected in the content tree. In the Message field, to indicate the relevant item, add a parameter to the value copied from the Click field of the /Sitecore/Content/Applications/Content Editor/Ribbons/Chunks/Show/Path item:

clipboard:copypathtoclipboard(id=$Target)

The updated context menu should appear almost immediately:

And function just like the Path command in the Show group on the Developer tab:

This entry was posted in Obsolete. Bookmark the permalink.

2 Responses to Add a Command to the Sitecore Item Context Menu

  1. Nilesh Thakkar says:

    Hello John,
    This is really helpful exercise. I really liked it, in-fact i like each topic of your blog. To make your blog more accurate, i m just drawing your kind attention towards a little typo here:

    In below paragraph, there is typo. Please correct it.

    “You can set access rights on the definition item to control who can use the command, or you can override the class specified in the /App_Config/commands.config file for the /configuration/command element named cliboard:copypathtoclipboard”

    It should be:

    cliPboard:copypathtoclipboard

  2. commodore73 says:

    @Nilesh: Thanks for the feedback and correction. It’s great to hear when someone benefits from something I’ve written.

    I recommend accessing my new blog at http://sitecorejohn.com rather than this old blog that I try not to maintain. I made the change you suggested both here and there.

    All the best,

    -John

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s