Need to add "publish" feature to the page editor, item editing section. (Under the "More" section would be ideal). How can I do this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
First you need to create a command class. The simplest version would be:
using System;
using Sitecore.Shell.Applications.WebEdit.Commands;
using Sitecore.Shell.Framework;
using Sitecore.Shell.Framework.Commands;
namespace my.assembly.namespace
{
[Serializable]
public class Publish : WebEditCommand
{
public override void Execute(CommandContext context)
{
if (context.Items.Length != 1)
return;
Items.Publish(context.Items[0]);
}
}
}
Register new command in Sitecore.config
(or Commands.config
):
<configuration>
<sitecore>
<commands>
<command name="my:publish" type="my.assembly.namespace.Publish,my.assembly"/>
</commands>
</sitecore>
</configuration>
Then:
- Login to Sitecore Desktop
- Switch database to core
- Duplicate
/sitecore/content/Applications/WebEdit/Common Field Buttons/Edit related item
- Rename new item to
Publish related item
- Set
Click
property of this item tomy:publish
- Change other properties of the item (
Header
,Icon
,Tooltip
) - Switch database back to master
- Open Page Editor and test the new command (it should open the standard publishing popup with the related item ID as a parameter in URL).
回答2:
We can achieve it without any code change.
<command name="webedit:publish" type="Sitecore.Shell.Framework.Commands.PublishItem,Sitecore.Kernel" />
Add the above entry in Commands.config file. This file is available in include folder.
- Login to Sitecore Desktop
- Switch database to core
- Duplicate /sitecore/content/Applications/WebEdit/Common Field Buttons/Edit related item
- Rename new item to Publish related item
- Set Click property of this item to chrome:common:edititem({command:"webedit:publish"})
- Switch database back to master
- Open Page Editor and test the new command (it should open the standard publishing popup with the related item ID as a parameter in URL).
Thanks
Fenil