添加页面编辑器"保存并发布"按钮

kru*_*rul 6 .net customization sitecore sitecore6 page-editor

我想在网站页面编辑器上的"保存并关闭"按钮旁边提供另一个按钮,该按钮将在按下后触发保存和发布操作.我去了核心并制作了一份我想要修改的"保存并关闭"按钮.

在此输入图像描述

我会将此按钮称为"保存并发布",但现在我有点好奇,如果我必须修改javascript以包含我的自定义调用(让我们说javascript:scSave("myPublish:saveAndPublish"))

我正在按照这篇文章挂钩管道并完成操作,但不确定这是否是正确的方法.

有什么建议?

Dan*_*vay 4

您需要做的是在 App_Config/Commands.config 中定义自定义命令:

<command name="myPublish:saveAndPublish" 
type="YourNamespace.YourCommand, YourAssembly" />
Run Code Online (Sandbox Code Playgroud)

任何自定义命令都需要子类化 Sitecore.Shell.Framework.Commands.Command 并重写该方法public override void Execute(CommandContext context)

使用自定义命令调用 PublishItem 命令:

public override void Execute(CommandContext context)
{
    var publishCommand = new PublishItem();
    publishCommand.Execute(context);
}
Run Code Online (Sandbox Code Playgroud)

需要注意以下几点:

  • 这在 Firefox 中对我有用,但在 Chrome 中不起作用,其中项目未保存。scSave使用大量前端 JavaScript,因此这似乎是 Sitecore Chrome 支持的一个错误。
  • 奇怪的是,该语法scSave("item:publish")不起作用,但从自定义命令间接调用 PublishComand 却起作用。如果有人知道这是为什么,请评论!
  • scSave 仅在从WebEditButton (/sitecore/templates/System/WebEdit/WebEdit Button)调用时有效,而不是从功能区按钮 ('/sitecore/templates/System/Ribbon/Large Button') 或 ('/sitecore/templates/System /功能区/小按钮')。
  • WebEditButton 必须位于功能区层次结构的顶部 ('/sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Buttons')。如果将其放置在其中一个块上(例如“新建”、“编辑”等),它将不会渲染。
  • 创建WebEditButton时,如果要控制页面编辑器上显示的图标,则需要通过Raw Values设置Data/Icon。否则,该值将保存到外观/图标,它控制内容项的图标,而不是页面编辑器按钮。这是由于内容编辑器的错误造成的。