From 4e5019d5af2f0785e95fd1bc885e62da2e2c2448 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 11 May 2014 21:32:15 +0200 Subject: [PATCH] U4-4851 - Umbraco.Field legacy names --- src/Umbraco.Web/umbraco.presentation/item.cs | 26 ++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/item.cs b/src/Umbraco.Web/umbraco.presentation/item.cs index 0920618f60..9e0a41fb54 100644 --- a/src/Umbraco.Web/umbraco.presentation/item.cs +++ b/src/Umbraco.Web/umbraco.presentation/item.cs @@ -78,26 +78,38 @@ namespace umbraco else { //check for published content and get its value using that - if (publishedContent != null) + if (publishedContent != null && publishedContent.HasProperty(_fieldName)) { var pval = publishedContent.GetPropertyValue(_fieldName); var rval = pval == null ? string.Empty : pval.ToString(); _fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval; } - else if (elements[_fieldName] != null && string.IsNullOrEmpty(elements[_fieldName].ToString()) == false) - { + else + { //get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent) - _fieldContent = elements[_fieldName].ToString().Trim(); + var elt = elements[_fieldName]; + if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false) + _fieldContent = elt.ToString().Trim(); } //now we check if the value is still empty and if so we'll check useIfEmpty if (string.IsNullOrEmpty(_fieldContent)) { - if (string.IsNullOrEmpty(helper.FindAttribute(attributes, "useIfEmpty")) == false) + var altFieldName = helper.FindAttribute(attributes, "useIfEmpty"); + if (string.IsNullOrEmpty(altFieldName) == false) { - if (elements[helper.FindAttribute(attributes, "useIfEmpty")] != null && string.IsNullOrEmpty(elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString()) == false) + if (publishedContent != null && publishedContent.HasProperty(altFieldName)) { - _fieldContent = elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString().Trim(); + var pval = publishedContent.GetPropertyValue(altFieldName); + var rval = pval == null ? string.Empty : pval.ToString(); + _fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval; + } + else + { + //get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent) + var elt = elements[altFieldName]; + if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false) + _fieldContent = elt.ToString().Trim(); } } }