Hide Quick info in Sitecore through code

最后都变了- 提交于 2019-12-22 12:38:33

问题


I want to hide quick info section through code instead of unchecking the check box in Application Options dialog box. Can someone help in this?


回答1:


The following code does exactly what your looking for.

Add this code below:

namespace Custom.Framework.SC.Extensions.Pipelines
{
    using Sitecore.Pipelines.LoggedIn;
    using SC = Sitecore;

    /// <summary>The default quick info.</summary>
    public class DefaultQuickInfo : SC.Pipelines.LoggedIn.LoggedInProcessor
    {
        /// <summary>The process.</summary>
        /// <param name="args">The args.</param>
        public override void Process(LoggedInArgs args)
        {
            const string DefaultToVisible = "false";

            SC.Diagnostics.Assert.ArgumentNotNull(args, "args");
            SC.Diagnostics.Assert.IsTrue(
              SC.Security.Accounts.User.Exists(args.Username),
              args.Username);

            var user = SC.Security.Accounts.User.FromName(
              args.Username,
              true);

            SC.Diagnostics.Assert.IsNotNull(user, "user");

            var sitecoreDomain = SC.SecurityModel.DomainManager.GetDomain(
              "sitecore");

            SC.Diagnostics.Assert.IsNotNull(sitecoreDomain, "sitecoreDomain");

            if (user.Domain != sitecoreDomain
              || user.Name.ToLower().EndsWith("\\" + sitecoreDomain.AnonymousUserName))
            {
                SC.Diagnostics.Log.Warn(this + " : unexpected security domain or user : " + user.Name, this);
                return;
            }

            var key = "/" + args.Username + "/UserOptions.ContentEditor.ShowQuickInfo";

            if (string.IsNullOrEmpty(user.Profile[key]))
            {
                user.Profile[key] = DefaultToVisible;
                user.Profile.Save();
            }
        }
    }
}

Then patch in this configuration change to add the processor to the appropriate place:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <processors>
      <loggedin>
        <processor patch:after="processor[position()=last()]" type="Custom.Framework.SC.Extensions.Pipelines.DefaultQuickInfo, Custom.Framework.SC.Extensions" />
      </loggedin>
    </processors>
  </sitecore>
</configuration>


来源:https://stackoverflow.com/questions/30348656/hide-quick-info-in-sitecore-through-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!