-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25123.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{BE9C84E5-9011-4C7C-A1C9-4665EDA32945}") = "Sitecore.Support.157536", "Sitecore.Support.157536\Sitecore.Support.157536.csproj", "{7EA8D751-A203-4FAE-A154-0AED255EF49D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{7EA8D751-A203-4FAE-A154-0AED255EF49D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7EA8D751-A203-4FAE-A154-0AED255EF49D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7EA8D751-A203-4FAE-A154-0AED255EF49D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7EA8D751-A203-4FAE-A154-0AED255EF49D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
7 changes: 7 additions & 0 deletions
7
src/Sitecore.Support.157536/App_Config/Include/zzz/Sitecore.Support.157536.config
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> | ||
<sitecore> | ||
<commands> | ||
<command name="item:setlayoutdetails" type="Sitecore.Support.Shell.Framework.Commands.SetLayoutDetails, Sitecore.Support.157536" /> | ||
</commands> | ||
</sitecore> | ||
</configuration> |
169 changes: 169 additions & 0 deletions
169
src/Sitecore.Support.157536/Data/Fields/CustomLayoutField.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
namespace Sitecore.Support.Data.Fields | ||
{ | ||
using Sitecore.Collections; | ||
using Sitecore.Data.Items; | ||
using Sitecore.Diagnostics; | ||
using Sitecore.Pipelines.GetLayoutSourceFields; | ||
using Sitecore.Xml; | ||
using Sitecore.Xml.Patch; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
/// <summary> | ||
/// Bug #157536 | ||
/// The class is created instead of LayoutField in order to rewrite the SetFieldValue method. | ||
/// </summary> | ||
static class CustomLayoutField | ||
{ | ||
[Obsolete("Use GetLayoutSourceFieldsPipeline.Run(GetLayoutSourceFieldsArgs args) method instead.")] | ||
private static List<string> DoGetFieldValue(Sitecore.Data.Fields.Field field) | ||
{ | ||
Sitecore.Data.Items.Item item = field.Item; | ||
FieldCollection fields = item.Fields; | ||
IEnumerable<Lazy<string>> source = new Lazy<string>[] { new Lazy<string>(() => fields[FieldIDs.FinalLayoutField].GetValue(false, false) ?? fields[FieldIDs.FinalLayoutField].GetInheritedValue(false)), new Lazy<string>(() => fields[FieldIDs.LayoutField].GetValue(false, false) ?? fields[FieldIDs.LayoutField].GetInheritedValue(false)), new Lazy<string>(() => fields[FieldIDs.FinalLayoutField].GetStandardValue()), new Lazy<string>(() => fields[FieldIDs.LayoutField].GetStandardValue()) }; | ||
bool flag = item.Name == "__Standard Values"; | ||
bool flag2 = field.ID == FieldIDs.LayoutField; | ||
if (flag && flag2) | ||
{ | ||
source = source.Skip<Lazy<string>>(3); | ||
} | ||
else if (flag) | ||
{ | ||
source = source.Skip<Lazy<string>>(2); | ||
} | ||
else if (flag2) | ||
{ | ||
source = source.Skip<Lazy<string>>(1); | ||
} | ||
return (from x in source select x.Value).ToList<string>(); | ||
} | ||
|
||
public static string GetFieldValue(Sitecore.Data.Fields.Field field) | ||
{ | ||
Assert.ArgumentNotNull(field, "field"); | ||
Assert.IsTrue((field.ID == FieldIDs.LayoutField) || (field.ID == FieldIDs.FinalLayoutField), "The field is not a layout/renderings field"); | ||
GetLayoutSourceFieldsArgs args = new GetLayoutSourceFieldsArgs(field); | ||
bool flag = GetLayoutSourceFieldsPipeline.Run(args); | ||
List<string> list = new List<string>(); | ||
if (flag) | ||
{ | ||
list.AddRange(from fieldValue in args.FieldValuesSource select fieldValue.GetValue(false, false) ?? (fieldValue.GetInheritedValue(false) ?? fieldValue.GetValue(false, false, true, false, false))); | ||
list.AddRange(from fieldValue in args.StandardValuesSource select fieldValue.GetStandardValue()); | ||
} | ||
else | ||
{ | ||
list = DoGetFieldValue(field); | ||
} | ||
System.Collections.Generic.Stack<string> source = new System.Collections.Generic.Stack<string>(); | ||
string str = null; | ||
foreach (string str2 in list) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(str2)) | ||
{ | ||
if (XmlPatchUtils.IsXmlPatch(str2)) | ||
{ | ||
source.Push(str2); | ||
} | ||
else | ||
{ | ||
str = str2; | ||
break; | ||
} | ||
} | ||
} | ||
if (string.IsNullOrWhiteSpace(str)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
/// Bug #157536 | ||
/// CustomXmlDeltas is used instead XmlDeltas | ||
/// return source.Aggregate<string, string>(str, new Func<string, string, string>(XmlDeltas.ApplyDelta)); | ||
return source.Aggregate<string, string>(str, new Func<string, string, string>(CustomXmlDeltas.ApplyDelta)); | ||
} | ||
|
||
public static void SetFieldValue(Sitecore.Data.Fields.Field field, string value) | ||
{ | ||
Sitecore.Data.Fields.Field field2; | ||
Assert.ArgumentNotNull(field, "field"); | ||
Assert.ArgumentNotNull(value, "value"); | ||
Assert.IsTrue((field.ID == FieldIDs.LayoutField) || (field.ID == FieldIDs.FinalLayoutField), "The field is not a layout/renderings field"); | ||
string fieldValue = null; | ||
bool flag = field.Item.Name == "__Standard Values"; | ||
bool flag2 = field.ID == FieldIDs.LayoutField; | ||
if (flag && flag2) | ||
{ | ||
field2 = null; | ||
} | ||
else if (flag) | ||
{ | ||
field2 = field.Item.Fields[FieldIDs.LayoutField]; | ||
} | ||
else if (flag2) | ||
{ | ||
TemplateItem template = field.Item.Template; | ||
field2 = ((template != null) && (template.StandardValues != null)) ? template.StandardValues.Fields[FieldIDs.FinalLayoutField] : null; | ||
} | ||
else | ||
{ | ||
field2 = field.Item.Fields[FieldIDs.LayoutField]; | ||
} | ||
if (field2 != null) | ||
{ | ||
fieldValue = GetFieldValue(field2); | ||
} | ||
if (XmlUtil.XmlStringsAreEqual(value, fieldValue)) | ||
{ | ||
field.Reset(); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(fieldValue)) | ||
{ | ||
// The class XmlDeltas is rewritten. | ||
field.Value = CustomXmlDeltas.GetDelta(value, fieldValue); | ||
} | ||
else | ||
{ | ||
field.Value = value; | ||
} | ||
} | ||
|
||
public static void SetFieldValue(Sitecore.Data.Fields.Field field, string value, string baseValue) | ||
{ | ||
Assert.ArgumentNotNull(field, "field"); | ||
Assert.ArgumentNotNull(value, "value"); | ||
Assert.ArgumentNotNull(baseValue, "baseValue"); | ||
Assert.IsTrue((field.ID == FieldIDs.LayoutField) || (field.ID == FieldIDs.FinalLayoutField), "The field is not a layout/renderings field"); | ||
if (XmlUtil.XmlStringsAreEqual(value, baseValue)) | ||
{ | ||
field.Reset(); | ||
} | ||
else | ||
{ | ||
string delta; | ||
if (!string.IsNullOrWhiteSpace(baseValue)) | ||
{ | ||
/// Bug #157536 | ||
/// CustomXmlDeltas is used instead XmlDeltas | ||
/// delta = XmlDeltas.GetDelta(value, baseValue); | ||
delta = CustomXmlDeltas.GetDelta(value, baseValue); | ||
} | ||
else | ||
{ | ||
delta = value; | ||
} | ||
|
||
/// Bug #157536 | ||
/// CustomXmlDeltas is used instead XmlDeltas | ||
/// if (!XmlUtil.XmlStringsAreEqual(CustomXmlDeltas.ApplyDelta(baseValue, field.Value), XmlDeltas.ApplyDelta(baseValue, delta))) | ||
/// { | ||
/// field.Value = delta; | ||
/// } | ||
if (!XmlUtil.XmlStringsAreEqual(CustomXmlDeltas.ApplyDelta(baseValue, field.Value), CustomXmlDeltas.ApplyDelta(baseValue, delta))) | ||
{ | ||
field.Value = delta; | ||
} | ||
} | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Sitecore.Support.157536/Data/Fields/CustomXmlDeltas.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
namespace Sitecore.Support.Data.Fields | ||
{ | ||
using Sitecore.Data.Fields; | ||
using Sitecore.Diagnostics; | ||
using Sitecore.Xml; | ||
using System; | ||
using Xml.Patch; | ||
|
||
/// <summary> | ||
/// Bug #157536 | ||
/// The class is created instead of XmlDeltas. | ||
/// </summary> | ||
public static class CustomXmlDeltas | ||
{ | ||
public static string ApplyDelta(string baseValue, string delta) | ||
{ | ||
Assert.ArgumentNotNull(baseValue, "baseValue"); | ||
if (!Sitecore.Xml.Patch.XmlPatchUtils.IsXmlPatch(delta)) | ||
{ | ||
return baseValue; | ||
} | ||
System.Xml.XmlDocument document = XmlUtil.LoadXml(delta); | ||
Assert.IsNotNull(document, "Layout Delta is not a valid XML"); | ||
System.Xml.XmlNode documentElement = document.DocumentElement; | ||
Assert.IsNotNull(documentElement, "Xml document root element is missing (delta)"); | ||
System.Xml.XmlDocument document2 = XmlUtil.LoadXml(baseValue); | ||
Assert.IsNotNull(document2, "Layout Value is not a valid XML"); | ||
System.Xml.XmlNode node2 = document2.DocumentElement; | ||
Assert.IsNotNull(node2, "Xml document root element is missing (base)"); | ||
new Sitecore.Xml.Patch.XmlPatcher("s", "p").Merge(node2, documentElement); | ||
return node2.OuterXml; | ||
} | ||
|
||
public static string GetDelta(string layoutValue, string baseValue) | ||
{ | ||
System.Xml.XmlDocument original = XmlUtil.LoadXml(baseValue); | ||
if (original != null) | ||
{ | ||
System.Xml.XmlDocument modified = XmlUtil.LoadXml(layoutValue); | ||
if (modified == null) | ||
{ | ||
return layoutValue; | ||
} | ||
|
||
/// Bug #157536 | ||
/// | ||
/// System.Xml.XmlDocument delta = XmlDiffUtils.Compare(original, modified, XmlDiffUtils.GetDefaultElementIdentification(), XmlDiffUtils.GetDefaultPatchNamespaces()); | ||
/// if (XmlDiffUtils.IsEmptyDelta(delta)) | ||
/// { | ||
/// return string.Empty; | ||
/// } | ||
|
||
XmlDiffHelper diffHelper = new XmlDiffHelper(); | ||
System.Xml.XmlDocument delta = diffHelper.Compare(original, modified, diffHelper.GetDefaultElementIdentification(), diffHelper.GetDefaultPatchNamespaces()); | ||
|
||
if (diffHelper.IsEmptyDelta(delta)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
layoutValue = delta.DocumentElement.HasChildNodes ? delta.OuterXml : string.Empty; | ||
} | ||
return layoutValue; | ||
} | ||
|
||
public static string GetFieldValue(Field field, Func<Field, string> getBaseValue) | ||
{ | ||
Assert.ArgumentNotNull(field, "field"); | ||
Assert.ArgumentNotNull(getBaseValue, "getBaseValue"); | ||
string str = field.GetValue(false, false); | ||
if (string.IsNullOrEmpty(str)) | ||
{ | ||
return field.Value; | ||
} | ||
return ApplyDelta(getBaseValue(field), str); | ||
} | ||
|
||
public static string GetStandardValue(Field field) => | ||
field.GetStandardValue(); | ||
|
||
public static void SetFieldValue(Field field, string value) | ||
{ | ||
Assert.ArgumentNotNull(field, "field"); | ||
Assert.ArgumentNotNull(value, "value"); | ||
if (field.Item.Name == "__Standard Values") | ||
{ | ||
field.Value = value; | ||
} | ||
else | ||
{ | ||
field.Value = GetDelta(value, field.GetStandardValue()); | ||
} | ||
} | ||
|
||
public static Func<Field, string> WithEmptyValue(string emptyValue) => | ||
delegate (Field field) { | ||
string standardValue = field.GetStandardValue(); | ||
if ((standardValue != null) && (standardValue.Trim().Length != 0)) | ||
{ | ||
return standardValue; | ||
} | ||
return emptyValue; | ||
}; | ||
} | ||
} |
Oops, something went wrong.