Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog » Command
Viewing all articles
Browse latest Browse all 5

Open Media Library from Sitecore Page Editor

$
0
0

This article describes how you can add your own button to the Sitecore Page Editor.

In a previous post I explained how to edit hidden fields in the Page Editor. This post is about managing media contents, and to do so you need to open the Sitecore Media Library which is the best tool for managing ALT texts, image descriptions and so on.

Open Media Library from the Sitecore Page Editor

Open Media Library from the Sitecore Page Editor

To open the Media Library you first need to add a button to the Page Editor. Go to the CORE database and find the Web Edit application at /sitecore/content/Applications/WebEdit.

The Preview and the Web Edit has their own individual toolbars, at /sitecore/content/Applications/WebEdit/Ribbons/Preview and /sitecore/content/Applications/WebEdit/Ribbons/WebEdit, so if you like the button to be visible in either mode you add the button twice.

  • Add a new Strip template below the toolbars to create a new tab.
  • Add a new Chunk template below the Strip template to create a new section on the strip.
  • Add a new Large Button template below the Chunk template to create a new button on the chunk.
  • Find a suitable icon and in the “click” field, write “webedit:OpenMediaLibrary
New button to open media library

New button to open media library

Now on to the code. First you need to couple the webedit:OpenMediaLibrary to the underlying code. This is done by adding a new .config file below /app_config/include, and add the following contents:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="webedit:OpenMediaLibrary" type="MyCode.OpenMediaLibrary,MyDll"/>
    </commands>
  </sitecore>
</configuration>

The code to open the media library looks like this:

using Sitecore;
using Sitecore.Text;
using Sitecore.Web.UI.Sheer;
using Sitecore.Shell.Framework.Commands;

namespace MyCode
{

  public class OpenMediaLibrary : Command
  {
    public override void Execute([NotNull] CommandContext context)
    {
      var url = new UrlString("/sitecore/shell/Applications/Content Manager/default.aspx");
      var header = string.Empty;
      var applicationItem = Client.CoreDatabase.GetItem("{7B2EA99D-BA9D-45B8-83B3-B38ADAD50BB8}");
      if (applicationItem != null)
      {
        header = applicationItem["Display name"];
      }
      if (header.Length == 0)
      {
        header = "Media Library";
      }
      url.Add("he", header);
      url.Add("pa", "1");
      url.Add("ic", "Applications/16x16/photo_scenery.png");
      url.Add("mo", "media");
      url.Add("ro", ItemIDs.MediaLibraryRoot.ToString());
      SheerResponse.Eval("window.open('" + url + "', 'MediaLibrary', 'location=0,resizable=1')");
    }
  }
}

Thats it. You will now have access to the Media Library from the Page Editor.



Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles



Latest Images