This project is read-only.

Extending Media Library

Topics: Customizing Orchard
Jul 27, 2016 at 3:25 PM
I see that the Media Library has the ability to attach shapes to the navigation and actions. However I am trying to work out how to add an action shape to the actions so that I can have a new button added to the Media Library to invoke an action in my module.

From the 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
Still bit too green with Orchard, but feels like a hole in my understanding of using shapes and placing them. I don't think a part needs to be involved for a shape that renders button as there is nothing to be stored?
Jul 28, 2016 at 3:01 AM
Edited Jul 28, 2016 at 3:10 AM
I have managed to work this out. First return a new shape for the MediaLibraryExplorerPart in a MediaLibraryExplorerPartDriver
    public class MediaLibraryExplorerPartDriver : ContentPartDriver<MediaLibraryExplorerPart> {
        protected override DriverResult Display(MediaLibraryExplorerPart part, string displayType, dynamic shapeHelper) {
            return ContentShape("Parts_MediaLibraryExplorer_MyActionShape", () => shapeHelper.Parts_MediaLibraryExplorer_MyActionShape());
Then place in the Actions zone
  <Place Parts_MediaLibraryExplorer_MyActionShape="Actions:6" />
Then create template (Views/Parts/MediaLibraryExplorer.MyActionShape.cshtml) for the shape with the button to invoke the module controller action :)
@Html.ActionLink(T("Click Me").Text, "Index", "Admin", new { area = "Orchard.MyModule" }, new { id = "click-me-link", @class = "button" })
How easy was that?!
Marked as answer by pdiddy on 7/27/2016 at 7:03 PM