向 Orchard CMS 媒体库添加自定义操作
Add custom action to Orchard CMS Media Library
我看到媒体库能够将形状附加到导航和操作。但是,我正在尝试找出如何向动作添加动作形状,以便我可以将新按钮添加到媒体库以调用我的模块中的动作。
来自媒体库AdminController.cs:
// let other modules enhance the ui by providing custom navigation and actions
var explorer = Services.ContentManager.New("MediaLibraryExplorer");
explorer.Weld(new MediaLibraryExplorerPart());
var explorerShape = Services.ContentManager.BuildDisplay(explorer);
var viewModel = new MediaManagerIndexViewModel {
CustomActionsShapes = explorerShape.Actions, // <-- I need to have my shape that is rendered as a button in here
};
Orchard 仍然有点太新了,但在我对使用形状和放置它们的理解上感觉像是一个洞。我不认为渲染按钮的形状需要涉及一个部分,因为没有任何东西可以存储?
我已经设法解决了这个问题。首先 return MediaLibraryExplorerPartDriver
中 MediaLibraryExplorerPart 的新形状
public class MediaLibraryExplorerPartDriver : ContentPartDriver<MediaLibraryExplorerPart> {
protected override DriverResult Display(MediaLibraryExplorerPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_MediaLibraryExplorer_MyActionShape", () => shapeHelper.Parts_MediaLibraryExplorer_MyActionShape());
}
}
然后放在动作区
<Placement>
<Place Parts_MediaLibraryExplorer_MyActionShape="Actions:6" />
</Placement>
然后为带有按钮的形状创建模板 (Views/Parts/MediaLibraryExplorer.MyActionShape.cshtml) 以调用模块控制器操作:)
@Html.ActionLink(T("Click Me").Text, "Index", "Admin", new { area = "Orchard.MyModule" }, new { id = "click-me-link", @class = "button" })
这有多简单?!
我看到媒体库能够将形状附加到导航和操作。但是,我正在尝试找出如何向动作添加动作形状,以便我可以将新按钮添加到媒体库以调用我的模块中的动作。
来自媒体库AdminController.cs:
// let other modules enhance the ui by providing custom navigation and actions
var explorer = Services.ContentManager.New("MediaLibraryExplorer");
explorer.Weld(new MediaLibraryExplorerPart());
var explorerShape = Services.ContentManager.BuildDisplay(explorer);
var viewModel = new MediaManagerIndexViewModel {
CustomActionsShapes = explorerShape.Actions, // <-- I need to have my shape that is rendered as a button in here
};
Orchard 仍然有点太新了,但在我对使用形状和放置它们的理解上感觉像是一个洞。我不认为渲染按钮的形状需要涉及一个部分,因为没有任何东西可以存储?
我已经设法解决了这个问题。首先 return MediaLibraryExplorerPartDriver
中 MediaLibraryExplorerPart 的新形状public class MediaLibraryExplorerPartDriver : ContentPartDriver<MediaLibraryExplorerPart> {
protected override DriverResult Display(MediaLibraryExplorerPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_MediaLibraryExplorer_MyActionShape", () => shapeHelper.Parts_MediaLibraryExplorer_MyActionShape());
}
}
然后放在动作区
<Placement>
<Place Parts_MediaLibraryExplorer_MyActionShape="Actions:6" />
</Placement>
然后为带有按钮的形状创建模板 (Views/Parts/MediaLibraryExplorer.MyActionShape.cshtml) 以调用模块控制器操作:)
@Html.ActionLink(T("Click Me").Text, "Index", "Admin", new { area = "Orchard.MyModule" }, new { id = "click-me-link", @class = "button" })
这有多简单?!