Skip to content

Instantly share code, notes, and snippets.

@5up3rman
Last active October 12, 2016 13:27
Show Gist options
  • Save 5up3rman/a58547639624255da3fd2de1c96ae389 to your computer and use it in GitHub Desktop.
Save 5up3rman/a58547639624255da3fd2de1c96ae389 to your computer and use it in GitHub Desktop.
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;
mappedItem.Hide = true;
// Add Item to RuleContext
ruleContext.MappedItems.AddOrReplaceItem(mappedItem);
}
}
public class SetFieldNames<T> : RuleAction<T> where T : ContentEditorRuleContext
{
public string FieldName { get; set; }
public string NewTitle { get; set; }
public override void Apply(T ruleContext)
{
var mappedItem =
MappedItemExtensions.GetMappedItem(ruleContext.MappedItems, MappedItemType.Field, FieldName) ??
new MappedItem();
mappedItem.Type = MappedItemType.Field;
mappedItem.OriginalName = FieldName;
mappedItem.NewTitle = NewTitle;
// Add Item to RuleContext
ruleContext.MappedItems.AddOrReplaceItem(mappedItem);
}
}
public class SetShortDescription<T> : RuleAction<T> where T : ContentEditorRuleContext
{
public string FieldName { get; set; }
public string Text { get; set; }
public override void Apply(T ruleContext)
{
var mappedItem =
MappedItemExtensions.GetMappedItem(ruleContext.MappedItems, MappedItemType.Field, FieldName) ??
new MappedItem();
mappedItem.Type = MappedItemType.Field;
mappedItem.OriginalTitle = FieldName;
mappedItem.ShortDescription = Text;
// Add Item to RuleContext
ruleContext.MappedItems.AddOrReplaceItem(mappedItem);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment