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>