From bbeedb6c1bf0d89de5b652ba5e5ab5b118d2d11a Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 17 Mar 2014 12:27:37 +1100 Subject: [PATCH] Fixes: U4-4373 @Library.NodeById(-1).Id returns "0" instead of "-1"(6.2.0 beta) & U4-4374 @Model.NodeById(-1).DescendantsOrSelf().First().Id results in Excecption (6.2.0 beta) --- .../CompatibilityHelper.cs | 2 +- .../RazorDynamicNode/DynamicBackingItem.cs | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs b/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs index da14d57a38..a2166e82c0 100644 --- a/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs +++ b/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.umbraco.presentation if (doc == null) { - Id = -1; + Id = 0; return; } diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs index c748605264..ded21a3119 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs @@ -32,6 +32,16 @@ namespace umbraco.MacroEngines } public DynamicBackingItem(int Id) { + if (Id == -1) + { + //this is a special check, previously passing in -1 would return a real node, the root node. Though + // it has no properties (defaults apply), you could access descendants, children, etc... + //This is how this used to work before a large refactor - which I think may have broken other legacy logic too :( + + this.content = new NodeFactory.Node(Id); + return; + } + var n = CompatibilityHelper.ConvertToNode(UmbracoContext.Current.ContentCache.GetById(Id)); this.content = n; @@ -57,7 +67,19 @@ namespace umbraco.MacroEngines } else { - this.content = CompatibilityHelper.ConvertToNode(UmbracoContext.Current.ContentCache.GetById(Id)); + if (Id == -1) + { + //this is a special check, previously passing in -1 would return a real node, the root node. Though + // it has no properties (defaults apply), you could access descendants, children, etc... + //This is how this used to work before a large refactor - which I think may have broken other legacy logic too :( + + this.content = new NodeFactory.Node(Id); + } + else + { + this.content = CompatibilityHelper.ConvertToNode(UmbracoContext.Current.ContentCache.GetById(Id)); + } + this.Type = Type; } }