1
votes

I have tried to create a debug button as shown below taking reference from link#3 in bottom, I have compiled and configured the button in core database and configured the Commands.config but I am getting error message on the master database when I click from ribbon and sitecore admin client is restarted. I am not getting what the error message is points to.. !

Ribbon Button screen

Open in the debugger

Error Message Text

Control "system" does not exist on form. at Sitecore.Shell.Framework.Commands.CommandManager.GetMethodCommand(String command) at Sitecore.Shell.Framework.Commands.CommandManager.GetDispatchCommand(String command) at Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command) at Sitecore.Web.UI.Sheer.ClientPage.RaiseEvent() at Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e)

Error Message screen

Error Message screem

One more thing the link#2 mentioned in the bottom does not seems to contain the 'prototype zip available in the Resources section' as said by John in the blog post here.. can anyone see If I'm not wrong?

PS: link#1 is the old post to the link#2

Debug.cs code

using System;

namespace SitecoreDemo.Shell.Framework.Commands.System
{
    [Serializable]
    // implements the debug command on the Sitecore menu of the desktop
    // and in the ribbon of the Content Editor
    public class Debug : Sitecore.Shell.Framework.Commands.System.Debug
    {
        public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // validate arguments and processing context
            Sitecore.Diagnostics.Assert.ArgumentNotNull(context, "context");
            Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientPage");
            Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientResponse");

            // ensure the new browser window authenticates as the current CMS user
            // (in case the user formerly previewed as another user)
            Sitecore.Publishing.PreviewManager.RestoreUser();

            // open the new browser window
            Sitecore.Web.UI.Sheer.SheerResponse.Eval("window.open('" + this.GetDebuggingUrl(context) + "', '_blank');");
        }

        // construct a URL to launch the debugger
        private string GetDebuggingUrl(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // whether to use the sc_lang query string parameter to specify the language
            bool includeLanguage = Sitecore.Links.LinkManager.LanguageEmbedding != Sitecore.Links.LanguageEmbedding.Never;

            // URL of the debugging window defaults to home page of managed site
            Sitecore.Text.UrlString url = new Sitecore.Text.UrlString("/");

            // enable all debugging options
            url.Add("sc_debug", "1"); // enable the debugger
            url.Add("sc_prof", "1"); // enable profiling
            url.Add("sc_trace", "1"); // enable tracing
            url.Add("sc_ri", "1"); // enable rendering information

            // if the user has selected an item, ensure they have saved,
            // then debug the item in the database and language associated with that item
            if (context != null && context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
            {
                Sitecore.Context.ClientPage.ClientResponse.CheckModified(false);

                Sitecore.Data.Items.Item item = context.Items[0];
                url.Add("sc_database", item.Database.Name);
                url.Add("sc_itemid", item.ID.ToString());

                if (includeLanguage)
                {
                    url.Add("sc_lang", item.ID.ToString());
                }
            }

            // if the user has not selected an item,
            // if there is a content database, debug that database
            // using the content language
            else if (Sitecore.Context.ContentDatabase != null)
            {
                url.Add("sc_database", Sitecore.Context.ContentDatabase.Name);
                if (includeLanguage)
                {
                    url.Add("sc_lang", Sitecore.Context.ContentLanguage.Name);
                }
            }

            // return a URL to open the debugger
            return url.GetUrl();
        }

        public override Sitecore.Shell.Framework.Commands.CommandState QueryState(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // if the user has selected at least one item
            if (context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
            {
                // if that item does not specify a layout for any device, disable this command
                if (!this.HasLayoutForAnyDevice(context.Items[0]))
                {
                    return Sitecore.Shell.Framework.Commands.CommandState.Disabled;
                }
            }
            return base.QueryState(context);
        }

        // returns true if the item specifies a layout for any device
        protected bool HasLayoutForAnyDevice(Sitecore.Data.Items.Item item)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");

            // evaluate each device in the database containing the item
            foreach (Sitecore.Data.Items.DeviceItem compare in item.Database.Resources.Devices.GetAll())
            {
                // if the item specifies layout details for that device, return true
                if (item.Visualization.GetLayout(compare) != null)
                {
                    return true;
                }
            }

            // layout details for the item do not specify a layout for any device
            return false;
        }
    }
}

Reference links:

  1. Add a Button to the Sitecore Content Editor Ribbon to Debug Any Item in Any Database
  2. Update: Add Debug Command to Content Editor in the Sitecore ASP.NET CMS
  3. Professional Sitecore Development- Google Books
2
Harsh, can't see the Ribbon Button Screen and Error message screen images. Please can you add them. - Shriroop
Ribbon button screen is same as shown here and Error Message screen is dialog showing the provided Error Message Text in the question and dialog content heading is Sitecore has encountered a problem and needs to close. We are sorry for the inconvenience.. - Harsh Baid

2 Answers

0
votes

The prototype link has a zip file and contains the Debug.cs file. Code below

using System;

namespace Sitecore.Sharedsource.Shell.Framework.Commands.System
{
  [Serializable]
  public class Debug : Sitecore.Shell.Framework.Commands.Command
  {
    public override void Execute(
      Sitecore.Shell.Framework.Commands.CommandContext context)
    {
      Context.ClientPage.ClientResponse.CheckModified(false);
      Sitecore.Data.Database contentDatabase = Context.ContentDatabase;

      if ((context.Items != null) && (context.Items.Length == 1))
      {
        Sitecore.Data.Database database = context.Items[0].Database;
      }

      Sitecore.Text.UrlString webSiteUrl = 
        Sitecore.Sites.SiteContext.GetWebSiteUrl();
      webSiteUrl.Add("sc_debug", "1");

      if ((context.Items != null) && (context.Items.Length == 1))
      {
        Sitecore.Data.Items.Item item = context.Items[0];

        if (item.Visualization.Layout != null)
        {
          webSiteUrl.Add("sc_itemid", item.ID.ToString());
        }

        webSiteUrl.Add("sc_lang", item.Language.ToString());
      }

      if (contentDatabase != null)
      {
        webSiteUrl.Add("sc_database", contentDatabase.Name);
      }

      webSiteUrl.Add("sc_prof", "1");
      webSiteUrl.Add("sc_trace", "1");
      webSiteUrl.Add("sc_ri", "1");
      Context.ClientPage.ClientResponse.Eval(
        "window.open('" + webSiteUrl + "', '_blank')");
    }
  }
}

Let me know if this code helps you and will get back to you if I find any more information.

0
votes

The provided solution prototype at here on the blog post Update: Add Debug Command to Content Editor in the Sitecore ASP.NET CMS solved my issue, I have configured my own Debug.cs class file in the command and copied the Debug.item file from the solution prototype zip to folder location as specified in the post (and also mentioned below) and it is working now.

Added 'Debug Item' menu to contextual items for my purposes

For references in future check below the steps as shown on the blog post to configure the solution prototype that helped me.

To create the command definition item using the serialization file:

  1. Copy the Debug.item file from the prototype zip available in the Resources section at the end of this blog post to the /data/serialization/core/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish subdirectory of your Sitecore solution, where the /data folder is typically a sibling of the Website folder.
  2. Log into the Sitecore desktop as an administrator.
  3. Click the database icon in the lower right corner and then select Core from the menu that appears (as described in the Sitecore Client Configuration Cookbook).
  4. Open the Content Editor, navigate to the /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish item (copy that path to your clipboard, paste it into the search box above the content tree, press Enter, select the first result).
  5. On the Developer tab, in the Serialize group, click Revert Tree. If you right-click the /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish item in the content tree and then click Refresh from the submenu that appears, a new Debug item should appear.
  6. Remember to use the database icon to select the Master database.

PS: However when I had created the debug item myself in content editor from core database it was not working don't know why.