5

In my example, Sitecore PowerShell Extensions (SPE) patches the command in order to provide insert options.

Reviewing the ShowConfig.aspx I see the following:

<command name="item:new" type="Cognifide.PowerShell.Client.Commands.MenuItems.ItemNew, Cognifide.PowerShell" patch:source="Cognifide.PowerShell.config"/>

My concern is that when I patch over the same command name SPE will break.

Is there a way to support multiple command implementations? Perhaps this would make a great module!

Update 1

Based on Mark's feedback I came up with this quick script to determine what might be possible. The script just queries the items that are already in the list. Perhaps I could use this to determine if I should add more items to the list. Also, not sure how I could add my own dividers.

$commandName = "item:new"
$item = Get-Item -Path "master:" -ID "{A3572733-5062-43E9-A447-54698BC1C637}"
$commandContext = New-Object -TypeName Sitecore.Shell.Framework.Commands.CommandContext -ArgumentList $item

[Sitecore.Shell.Framework.Commands.CommandManager]::GetCommand($commandName).GetSubMenuItems($commandContext) | 
    Where-Object { $_.GetType().Name -eq 'MenuItem' } | Select-Object -Property header

Output

Here's what I think might work.

  1. Create a new insert options with condition and action to render the desired items.
  2. Figure out what happens when the user click the insert option.

Update 2

I found a solution by writing a module for it. See the answer below.

2 Answers 2

4

Not easily, no.

Commands are bound to that identifier string (e.g. "item:new") and that's how they are identified across the system.

You could override (replace) by inheriting the PowerShell command and calling it via base..

Another option

And perhaps the better one, if you need Insert Options, is to use the Rules Engine.

Depending on your specific use case, even out-of-the-box you have the ability to dynamically add Insert Options.

enter image description here

You can then extend this with custom Conditions and Actions as needed.

2

I finally found a solution, but required some light coding to get working. I've created a module for this solution in case anyone wants to do this without duplicating effort. Check it out here.

The solution involves a few steps.

  1. Override the ItemNew command with an implementation that will render the submenu for other classes.
  2. Patch the command with the list of class names.

Here's a single patch to both override the ItemNew command and add in the list of classes.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="item:new">
        <patch:attribute name="type">Westco.SS.Foundation.CommandExtender.Commands.ItemNew, Westco.SS.Foundation.CommandExtender</patch:attribute>
        <menucommands hint="list">
          <menucommand type="Cognifide.PowerShell.Client.Commands.MenuItems.ItemNew, Cognifide.PowerShell" />
          <menucommand type="Sitecore.SharedSource.Shell.Framework.Commands.MenuItems.ItemNew, Sitecore.SharedSource.CodeEditor" />
        </menucommands>
      </command>
    </commands>
  </sitecore>
</configuration>

As you can see, SPE is installed and the Code Editor module is still able to render the items.

Sample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.