Created
July 28, 2015 02:43
-
-
Save Azadehkhojandi/b92a0fbec5513d639cbf to your computer and use it in GitHub Desktop.
sitecore custom edit frame buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Sitecore; | |
using Sitecore.Configuration; | |
using Sitecore.Data; | |
using Sitecore.Data.Fields; | |
using Sitecore.Data.Items; | |
using Sitecore.Diagnostics; | |
using Sitecore.Pipelines.SetupEditFrame; | |
using SC = Sitecore; | |
//http://www.matthewkenny.com/2014/11/using-multiple-button-roots-on-a-sitecore-edit-frame/ | |
namespace Framework.Extension.Sitecore.Pipelines | |
{ | |
public class MultiRootEditFrameChromeData : SC.Pipelines.GetChromeData.GetEditFrameChromeData | |
{ | |
public override void Process(SC.Pipelines.GetChromeData.GetChromeDataArgs args) | |
{ | |
Assert.ArgumentNotNull(args, "args"); | |
Assert.IsNotNull(args.ChromeData, "Chrome Data"); | |
if (!"editFrame".Equals(args.ChromeType, StringComparison.OrdinalIgnoreCase)) | |
{ | |
// Don't do anything for non-editFrame chrome requests. | |
return; | |
} | |
Database database = Factory.GetDatabase("core"); | |
Assert.IsNotNull(database, "core"); | |
// args.CustomData["buttonsPath] is populated by the EditFrame | |
string buttonPaths = StringUtil.GetString(args.CustomData["buttonsPath"], Settings.WebEdit.DefaultButtonPath); | |
var buttons = new List<WebEditButton>(); | |
foreach (var buttonPath in buttonPaths.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)) | |
{ | |
var path = buttonPath; | |
if (!ID.IsID(path) && !path.StartsWith("/")) | |
{ | |
// Allow button paths to be relative to the edit frame button root | |
path = "/sitecore/content/Applications/WebEdit/Edit Frame Buttons/" + path; | |
} | |
Item item = database.GetItem(path); | |
if (item == null) | |
{ | |
Log.Error(string.Format("buttonRoot does not exist for edit frame -{0}", path),this); | |
continue; | |
} | |
if (item.HasChildren) | |
{ | |
buttons.AddRange(GetButtons(item)); | |
} | |
else | |
{ | |
var button = GetButton(item); | |
if (button != null) | |
{ | |
buttons.Add(button); | |
} | |
} | |
} | |
// Title can be set by the edit frame, so only do this if one hasn't been set | |
args.ChromeData.DisplayName = StringUtil.GetString(new[] { args.ChromeData.DisplayName, "Page Area" }); | |
AddButtonsToChromeData(buttons, args); | |
} | |
private WebEditButton GetButton(Item buttonItem) | |
{ | |
var webEditButton = this.ConvertToWebEditButton(buttonItem); | |
return webEditButton; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment