U4-4851 - Umbraco.Field legacy names

This commit is contained in:
Stephan
2014-05-11 21:32:15 +02:00
parent da0b935604
commit 4e5019d5af

View File

@@ -78,26 +78,38 @@ namespace umbraco
else else
{ {
//check for published content and get its value using that //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 pval = publishedContent.GetPropertyValue(_fieldName);
var rval = pval == null ? string.Empty : pval.ToString(); var rval = pval == null ? string.Empty : pval.ToString();
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval; _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) //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 //now we check if the value is still empty and if so we'll check useIfEmpty
if (string.IsNullOrEmpty(_fieldContent)) 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();
} }
} }
} }