Skip to content

Commit e0c45b1

Browse files
Fix clearing additional parameters in the "Layout Details" when removing sublayout item
1 parent fe4d38f commit e0c45b1

File tree

7 files changed

+284
-0
lines changed

7 files changed

+284
-0
lines changed

src/Sitecore.Support.159068.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25123.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{CB0FCA4B-AC4D-4762-9FAA-F1491C525983}") = "Sitecore.Support.159068", "Sitecore.Support.159068\Sitecore.Support.159068.csproj", "{25838F45-62CA-40D4-8194-8861E410C141}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{25838F45-62CA-40D4-8194-8861E410C141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{25838F45-62CA-40D4-8194-8861E410C141}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{25838F45-62CA-40D4-8194-8861E410C141}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{25838F45-62CA-40D4-8194-8861E410C141}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
2+
<sitecore>
3+
<fieldTypes>
4+
<fieldType name="Layout">
5+
<patch:attribute name="type">Sitecore.Support.Data.Fields.LayoutField,Sitecore.Support.159068</patch:attribute>
6+
</fieldType>
7+
</fieldTypes>
8+
</sitecore>
9+
</configuration>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
namespace Sitecore.Support.Data.Fields
2+
{
3+
using Sitecore.Data.Fields;
4+
using Sitecore.Data.Items;
5+
using Sitecore.Diagnostics;
6+
using Sitecore.Layouts;
7+
using Sitecore.Links;
8+
using Sitecore.Text;
9+
using Sitecore.Xml;
10+
using System;
11+
using System.Collections;
12+
using System.Xml;
13+
using System.Xml.Linq;
14+
15+
public class LayoutField : Sitecore.Data.Fields.LayoutField
16+
{
17+
private readonly XmlDocument data;
18+
19+
public LayoutField(Field innerField) : base(innerField)
20+
{
21+
Assert.ArgumentNotNull(innerField, "innerField");
22+
this.data = this.LoadData();
23+
}
24+
25+
public LayoutField(Item item) : this(item.Fields[FieldIDs.FinalLayoutField])
26+
{
27+
}
28+
29+
public LayoutField(Field innerField, string runtimeValue) : base(innerField, runtimeValue)
30+
{
31+
Assert.ArgumentNotNull(innerField, "innerField");
32+
Assert.ArgumentNotNullOrEmpty(runtimeValue, "runtimeValue");
33+
this.data = this.LoadData();
34+
}
35+
36+
private RenderingParametersFieldCollection GetParametersFields(Item layoutItem, string renderingParameters)
37+
{
38+
RenderingParametersFieldCollection fields;
39+
UrlString str = new UrlString(renderingParameters);
40+
RenderingParametersFieldCollection.TryParse(layoutItem, str, out fields);
41+
return fields;
42+
}
43+
44+
private XmlDocument LoadData()
45+
{
46+
string str = base.Value;
47+
if (!string.IsNullOrEmpty(str))
48+
{
49+
return XmlUtil.LoadXml(str);
50+
}
51+
return XmlUtil.LoadXml("<r/>");
52+
}
53+
54+
public override void RemoveLink(ItemLink itemLink)
55+
{
56+
Assert.ArgumentNotNull(itemLink, "itemLink");
57+
string str = base.Value;
58+
if (!string.IsNullOrEmpty(str))
59+
{
60+
LayoutDefinition definition = LayoutDefinition.Parse(str);
61+
ArrayList list = definition.Devices;
62+
if (list != null)
63+
{
64+
string b = itemLink.TargetItemID.ToString();
65+
for (int i = list.Count - 1; i >= 0; i--)
66+
{
67+
DeviceDefinition definition2 = list[i] as DeviceDefinition;
68+
if (definition2 != null)
69+
{
70+
if (definition2.ID == b)
71+
{
72+
list.Remove(definition2);
73+
}
74+
else if (definition2.Layout == b)
75+
{
76+
definition2.Layout = null;
77+
}
78+
else
79+
{
80+
if (definition2.Placeholders != null)
81+
{
82+
string str3 = itemLink.TargetPath;
83+
bool flag = false;
84+
for (int j = definition2.Placeholders.Count - 1; j >= 0; j--)
85+
{
86+
PlaceholderDefinition definition3 = definition2.Placeholders[j] as PlaceholderDefinition;
87+
if ((definition3 != null) && (string.Equals(definition3.MetaDataItemId, str3, StringComparison.InvariantCultureIgnoreCase) || string.Equals(definition3.MetaDataItemId, b, StringComparison.InvariantCultureIgnoreCase)))
88+
{
89+
definition2.Placeholders.Remove(definition3);
90+
flag = true;
91+
}
92+
}
93+
if (flag)
94+
{
95+
continue;
96+
}
97+
}
98+
if (definition2.Renderings != null)
99+
{
100+
for (int k = definition2.Renderings.Count - 1; k >= 0; k--)
101+
{
102+
RenderingDefinition definition4 = definition2.Renderings[k] as RenderingDefinition;
103+
if (definition4 != null)
104+
{
105+
if (definition4.Datasource == itemLink.TargetPath)
106+
{
107+
definition4.Datasource = string.Empty;
108+
}
109+
if (definition4.ItemID == b)
110+
{
111+
definition2.Renderings.Remove(definition4);
112+
}
113+
if (definition4.Datasource == b)
114+
{
115+
definition4.Datasource = string.Empty;
116+
}
117+
if (!string.IsNullOrEmpty(definition4.Parameters))
118+
{
119+
Item layoutItem = base.InnerField.Database.GetItem(definition4.ItemID);
120+
if (layoutItem != null)
121+
{
122+
RenderingParametersFieldCollection parametersFields = this.GetParametersFields(layoutItem, definition4.Parameters);
123+
foreach (CustomField field in parametersFields.Values)
124+
{
125+
if (!string.IsNullOrEmpty(field.Value))
126+
{
127+
field.RemoveLink(itemLink);
128+
}
129+
}
130+
}
131+
}
132+
if (definition4.Rules != null)
133+
{
134+
RulesField field2 = new RulesField(base.InnerField, definition4.Rules.ToString());
135+
field2.RemoveLink(itemLink);
136+
definition4.Rules = XElement.Parse(field2.Value);
137+
}
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}
144+
base.Value = definition.ToXml();
145+
}
146+
}
147+
}
148+
}
149+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyTitle("Sitecore.Support.159068")]
5+
[assembly: AssemblyProduct("Sitecore.Support.159068")]
6+
[assembly: ComVisible(false)]
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProductVersion>
8+
</ProductVersion>
9+
<SchemaVersion>2.0</SchemaVersion>
10+
<ProjectGuid>{25838F45-62CA-40D4-8194-8861E410C141}</ProjectGuid>
11+
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
12+
<OutputType>Library</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<RootNamespace>Sitecore.Support</RootNamespace>
15+
<AssemblyName>Sitecore.Support.159068</AssemblyName>
16+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
17+
<UseIISExpress>true</UseIISExpress>
18+
<IISExpressSSLPort />
19+
<IISExpressAnonymousAuthentication />
20+
<IISExpressWindowsAuthentication />
21+
<IISExpressUseClassicPipelineMode />
22+
<UseGlobalApplicationHostFile />
23+
<TargetFrameworkProfile />
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugSymbols>true</DebugSymbols>
27+
<DebugType>full</DebugType>
28+
<Optimize>false</Optimize>
29+
<OutputPath>bin\</OutputPath>
30+
<DefineConstants>DEBUG;TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
35+
<DebugType>pdbonly</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\</OutputPath>
38+
<DefineConstants>TRACE</DefineConstants>
39+
<ErrorReport>prompt</ErrorReport>
40+
<WarningLevel>4</WarningLevel>
41+
</PropertyGroup>
42+
<ItemGroup>
43+
<Reference Include="Sitecore.Kernel">
44+
<HintPath>..\packages\SC.Sitecore.Kernel.8.2.2\lib\Sitecore.Kernel.dll</HintPath>
45+
<Private>False</Private>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Drawing" />
49+
<Reference Include="System.Web" />
50+
<Reference Include="System.Xml" />
51+
<Reference Include="System.Configuration" />
52+
<Reference Include="System.Xml.Linq" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="Data\Fields\LayoutField.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Content Include="App_Config\Include\zzz\Sitecore.Support.159068.config" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<None Include="packages.config" />
63+
<None Include="web.config" />
64+
</ItemGroup>
65+
<PropertyGroup>
66+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
67+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
68+
</PropertyGroup>
69+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
70+
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
71+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
72+
<ProjectExtensions>
73+
<VisualStudio>
74+
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
75+
<WebProjectProperties>
76+
<UseIIS>True</UseIIS>
77+
<AutoAssignPort>True</AutoAssignPort>
78+
<DevelopmentServerPort>0</DevelopmentServerPort>
79+
<DevelopmentServerVPath>/</DevelopmentServerVPath>
80+
<IISUrl>http://localhost:54061/</IISUrl>
81+
<NTLMAuthentication>False</NTLMAuthentication>
82+
<UseCustomServer>False</UseCustomServer>
83+
<CustomServerUrl>
84+
</CustomServerUrl>
85+
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
86+
</WebProjectProperties>
87+
</FlavorProperties>
88+
</VisualStudio>
89+
</ProjectExtensions>
90+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="SC.Sitecore.Kernel" version="8.2.2" targetFramework="net452" />
4+
</packages>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<!-- Do not change this file - it must be empty, see https://github.com/SitecoreSupport/PatchCreator/issues/13 -->
4+
</configuration>

0 commit comments

Comments
 (0)