Fixed a bug where if the ContentType (DocumentType) tree was a different tree to the Content or Media (Node) tree then the datatype lookup could fail when retrieving a property recursively.

If GetProperty recursively walked up the content tree to the first node that defined the property and eventutally found it, and the NodeType[Alias] of the node it was found on was not a parent of the original content's node type, then the lookup would fail.
Changed DynamicBackingItem.GetProperty (and PropertyResult class) to return the Node/Context where the property is being returned from and used this context's NodeTypeAlias as the in the data type lookup.
This commit is contained in:
agrath@gmail.com
2011-07-03 09:32:29 -12:00
parent 75d15cdc31
commit 1164ea3ab1
3 changed files with 42 additions and 17 deletions

View File

@@ -78,7 +78,7 @@ namespace umbraco.MacroEngines
}
}
public IProperty GetProperty(string alias)
public PropertyResult GetProperty(string alias)
{
if (IsNull()) return null;
if (Type == DynamicBackingItemType.Content)
@@ -91,13 +91,13 @@ namespace umbraco.MacroEngines
}
}
private IProperty GetPropertyInternal(string alias, INode content)
private PropertyResult GetPropertyInternal(string alias, INode content)
{
bool propertyExists = false;
var prop = content.GetProperty(alias, out propertyExists);
if (prop != null)
{
return new PropertyResult(prop);
return new PropertyResult(prop) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
else
{
@@ -106,7 +106,7 @@ namespace umbraco.MacroEngines
prop = content.GetProperty(alias.Substring(0, 1).ToLower() + alias.Substring((1)), out propertyExists);
if (prop != null)
{
return new PropertyResult(prop);
return new PropertyResult(prop) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
else
{
@@ -129,20 +129,20 @@ namespace umbraco.MacroEngines
}
if (result != null)
{
return new PropertyResult(alias, string.Format("{0}", result), Guid.Empty);
return new PropertyResult(alias, string.Format("{0}", result), Guid.Empty) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
}
}
}
return null;
}
private IProperty GetPropertyInternal(string alias, ExamineBackedMedia content)
private PropertyResult GetPropertyInternal(string alias, ExamineBackedMedia content)
{
bool propertyExists = false;
var prop = content.GetProperty(alias, out propertyExists);
if (prop != null)
{
return new PropertyResult(prop);
return new PropertyResult(prop) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
else
{
@@ -151,7 +151,7 @@ namespace umbraco.MacroEngines
prop = content.GetProperty(alias.Substring(0, 1).ToLower() + alias.Substring((1)), out propertyExists);
if (prop != null)
{
return new PropertyResult(prop);
return new PropertyResult(prop) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
else
{
@@ -172,36 +172,51 @@ namespace umbraco.MacroEngines
}
if (result != null)
{
return new PropertyResult(alias, string.Format("{0}", result), Guid.Empty);
return new PropertyResult(alias, string.Format("{0}", result), Guid.Empty) { ContextAlias = content.NodeTypeAlias, ContextId = content.Id };
}
}
}
}
return null;
}
public IProperty GetProperty(string alias, out bool propertyExists)
public PropertyResult GetProperty(string alias, out bool propertyExists)
{
if (IsNull())
{
propertyExists = false;
return null;
}
PropertyResult property = null;
IProperty innerProperty = null;
if (Type == DynamicBackingItemType.Content)
{
return content.GetProperty(alias, out propertyExists);
innerProperty = content.GetProperty(alias, out propertyExists);
if (innerProperty != null)
{
property = new PropertyResult(innerProperty);
property.ContextAlias = content.NodeTypeAlias;
property.ContextId = content.Id;
}
}
else
{
return media.GetProperty(alias, out propertyExists);
innerProperty = media.GetProperty(alias, out propertyExists);
if (innerProperty != null)
{
property = new PropertyResult(innerProperty);
property.ContextAlias = media.NodeTypeAlias;
property.ContextId = media.Id;
}
}
return property;
}
public IProperty GetProperty(string alias, bool recursive)
public PropertyResult GetProperty(string alias, bool recursive)
{
bool propertyExists = false;
return GetProperty(alias, recursive, out propertyExists);
}
public IProperty GetProperty(string alias, bool recursive, out bool propertyExists)
public PropertyResult GetProperty(string alias, bool recursive, out bool propertyExists)
{
if (!recursive)
{
@@ -213,7 +228,7 @@ namespace umbraco.MacroEngines
return null;
}
DynamicBackingItem context = this;
IProperty prop = this.GetProperty(alias, out propertyExists);
PropertyResult prop = this.GetProperty(alias, out propertyExists);
while (prop == null || string.IsNullOrEmpty(prop.Value))
{
context = context.Parent;

View File

@@ -406,7 +406,9 @@ namespace umbraco.MacroEngines
{
throw new ArgumentNullException("No node alias or property alias available. Unable to look up the datatype of the property you are trying to fetch.");
}
Guid dataType = ContentType.GetDataType(n.NodeTypeAlias, data.Alias);
//contextAlias is the node which the property data was returned from
Guid dataType = ContentType.GetDataType(data.ContextAlias, data.Alias);
if (RazorDataTypeModelTypes == null)
{
@@ -421,7 +423,12 @@ namespace umbraco.MacroEngines
Guid g = RazorDataTypeModelAttribute.DataTypeEditorId;
return new KeyValuePair<Guid, Type>(g, type);
})
.ForEach(item => RazorDataTypeModelTypes.Add(item.Key, item.Value));
.ForEach(item => {
if(!RazorDataTypeModelTypes.ContainsKey(item.Key))
{
RazorDataTypeModelTypes.Add(item.Key, item.Value);
}
});
}
if (RazorDataTypeModelTypes.ContainsKey(dataType))
{

View File

@@ -57,5 +57,8 @@ namespace umbraco.MacroEngines
{
return !string.IsNullOrWhiteSpace(Value);
}
public int ContextId { get; set; }
public string ContextAlias { get; set; }
}
}