Skip to content

Instantly share code, notes, and snippets.

using System.Text.RegularExpressions;
using Sitecore.Mvc.Presentation;
using Sitecore.Mvc.Pipelines.Response.GetRenderer;
namespace Paragon.Sc.Mvc.Pipelines
{
public class GetViewRenderer : Sitecore.Mvc.Pipelines.Response.GetRenderer.GetViewRenderer
{
public override void Process(GetRendererArgs args)
{
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<mvc.getrenderer>
<processor
patch:instead="processor[@type='type=Sitecore.Mvc.Pipelines.Response.GetRenderer.GetViewRenderer, Sitecore.Mvc']"
type="Paragon.Website.Sc.Mvc.Pipelines.GetViewRenderer, Paragon.Website.Sc.Mvc" />
</mvc.getrenderer>
</pipelines>
</sitecore>
@5up3rman
5up3rman / Paragon.Sc.ContentEditor.config
Created October 11, 2016 19:24
Customized Content Editor Config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<renderContentEditor>
<processor
patch:instead="processor[@type='Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderStandardContentEditor, Sitecore.Client']"
type="Paragon.Sc.ContentEditor.Pipelines.RenderContentEditor.RenderCustomizedContentEditor, Paragon.Sc.ContentEditor" />
</renderContentEditor>
</pipelines>
</sitecore>
@5up3rman
5up3rman / RenderCustomizedContentEditor.cs
Last active October 12, 2016 12:34
RenderCustomizedContentEditor Pipeline
public class RenderCustomizedContentEditor
{
public void Process(RenderContentEditorArgs args)
{
var editorFormatter = new EditorFormatter(args);
editorFormatter.RenderSections(args.Parent, args.Sections, args.ReadOnly);
}
}
@5up3rman
5up3rman / ContentEditorRuleContext.cs
Last active October 12, 2016 12:57
Rule Context and Processor
[Serializable]
public class ContentEditorRuleContext : RuleContext, ISerializable
{
public List<IMappedItem> MappedItems { get; set; } = new List<IMappedItem>();
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
}
@5up3rman
5up3rman / MappedItem.cs
Last active October 12, 2016 13:00
Mapped Item
public enum MappedItemType { Section, Field }
public class MappedItem
{
public MappedItemType Type { get; set; }
public string OriginalName { get; set; }
public string NewTitle { get; set; }
public string ShortDescription { get; set; }
public bool Hide { get; set; }
}
@5up3rman
5up3rman / HideFields.cs
Last active October 12, 2016 13:27
Rule Actions
public class HideFields<T> : RuleAction<T> where T : ContentEditorRuleContext
{
public string FieldName { get; set; }
public override void Apply(T ruleContext)
{
var mappedItem =
MappedItemExtensions.GetItem(ruleContext.MappedItems, MappedItemType.Field, FieldName) ??
new MappedItem();
mappedItem.Type = MappedItemType.Field;
mappedItem.OriginalName = FieldName;
public class EditorFormatter
{
public RenderContentEditorArgs Arguments { get; set; }
public List<IMappedItem> MappedItems { get; set; } = new List<IMappedItem>();
public EditorFormatter(RenderContentEditorArgs args)
{
Arguments = args;
// We want to make sure the Item is under the Content Node and that the item is not null.
if (args.Item == null || !args.Item.Paths.IsContentItem)return;
// Run the rules and set it to MappedItems
@5up3rman
5up3rman / MappedItemExtensions.cs
Last active October 12, 2016 13:51
MappedItemExtensions
public static class MappedItemExtensions
{
public static IMappedItem GetMappedItem(IEnumerable<IMappedItem> mappedItems, MappedItemType itemType, string originalName)
{
return mappedItems.FirstOrDefault(x => x.OriginalName.EndsWith(originalName) && x.Type.Equals(itemType));
}
public static IEnumerable<T> AddOrReplaceItem<T>(this List<T> list, T item) where T : IMappedItem
{
var idx = list.FindIndex(x => x.OriginalName.Equals(item.OriginalName));
if (idx.Equals(-1))
@5up3rman
5up3rman / GlassEditableExample.cshtml
Created October 28, 2016 11:27
P Tags in Glass().Editable
@Html.Glass().Editable(model, x => x.Summary, x => $"<p>{x.Summary}</p>"))