Incorporate Stephane's feedback: if we already know we're getting list of int or udi, we don't need to cast, or even test for the PropertyEditorAlias
This commit is contained in:
@@ -15,7 +15,6 @@ namespace Umbraco.Web.Models
|
||||
public bool IsInternal { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public RelatedLinkType Type { get; set; }
|
||||
[JsonProperty("content")]
|
||||
public IPublishedContent Content { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,25 +111,19 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
if ((propertyType.PropertyTypeAlias != null && PropertiesToExclude.Contains(propertyType.PropertyTypeAlias.ToLower(CultureInfo.InvariantCulture))) == false)
|
||||
{
|
||||
IPublishedContent content;
|
||||
switch (propertyType.PropertyEditorAlias)
|
||||
if (source is int)
|
||||
{
|
||||
case Constants.PropertyEditors.ContentPickerAlias:
|
||||
int sourceInt;
|
||||
if (int.TryParse(source.ToString(), out sourceInt))
|
||||
{
|
||||
content = UmbracoContext.Current.ContentCache.GetById(sourceInt);
|
||||
return content;
|
||||
}
|
||||
break;
|
||||
case Constants.PropertyEditors.ContentPicker2Alias:
|
||||
Udi udi;
|
||||
if (Udi.TryParse(source.ToString(), out udi))
|
||||
{
|
||||
content = udi.ToPublishedContent();
|
||||
if (content != null)
|
||||
return content;
|
||||
}
|
||||
break;
|
||||
var sourceInt = (int)source;
|
||||
content = UmbracoContext.Current.ContentCache.GetById(sourceInt);
|
||||
if(content != null)
|
||||
return content;
|
||||
}
|
||||
else
|
||||
{
|
||||
var sourceUdi = source as Udi;
|
||||
content = sourceUdi.ToPublishedContent();
|
||||
if (content != null)
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,28 +44,20 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
if (UmbracoContext.Current != null)
|
||||
{
|
||||
IPublishedContent member;
|
||||
switch (propertyType.PropertyEditorAlias)
|
||||
if (source is int)
|
||||
{
|
||||
case Constants.PropertyEditors.MemberPickerAlias:
|
||||
int sourceInt;
|
||||
if (int.TryParse(source.ToString(), out sourceInt))
|
||||
{
|
||||
var membershipHelper = new MembershipHelper(UmbracoContext.Current);
|
||||
member = membershipHelper.GetById((int)source);
|
||||
return member;
|
||||
}
|
||||
break;
|
||||
case Constants.PropertyEditors.MemberPicker2Alias:
|
||||
Udi udi;
|
||||
if (Udi.TryParse(source.ToString(), out udi))
|
||||
{
|
||||
member = udi.ToPublishedContent();
|
||||
if (member != null)
|
||||
return member;
|
||||
}
|
||||
break;
|
||||
var membershipHelper = new MembershipHelper(UmbracoContext.Current);
|
||||
member = membershipHelper.GetById((int)source);
|
||||
if (member != null)
|
||||
return member;
|
||||
}
|
||||
else
|
||||
{
|
||||
var sourceUdi = source as Udi;
|
||||
member = sourceUdi.ToPublishedContent();
|
||||
if (member != null)
|
||||
return member;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return source;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
{
|
||||
if (UmbracoConfig.For.UmbracoSettings().Content.EnablePropertyValueConverters)
|
||||
{
|
||||
return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias)
|
||||
return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias)
|
||||
|| propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias);
|
||||
}
|
||||
return false;
|
||||
@@ -99,32 +99,28 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
Link = linkData.Link
|
||||
};
|
||||
|
||||
switch (propertyType.PropertyEditorAlias)
|
||||
int contentId;
|
||||
if (int.TryParse(relatedLink.Link, out contentId))
|
||||
{
|
||||
case Constants.PropertyEditors.RelatedLinksAlias:
|
||||
int contentId;
|
||||
if (int.TryParse(relatedLink.Link, out contentId))
|
||||
{
|
||||
relatedLink.Id = contentId;
|
||||
relatedLink = CreateLink(relatedLink);
|
||||
}
|
||||
break;
|
||||
case Constants.PropertyEditors.RelatedLinks2Alias:
|
||||
var strLinkId = linkData.Link;
|
||||
var udiAttempt = strLinkId.TryConvertTo<Udi>();
|
||||
if (udiAttempt.Success)
|
||||
{
|
||||
var content = udiAttempt.Result.ToPublishedContent();
|
||||
if (content != null)
|
||||
{
|
||||
relatedLink.Id = content.Id;
|
||||
relatedLink = CreateLink(relatedLink);
|
||||
relatedLink.Content = content;
|
||||
}
|
||||
}
|
||||
break;
|
||||
relatedLink.Id = contentId;
|
||||
relatedLink = CreateLink(relatedLink);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var strLinkId = linkData.Link;
|
||||
var udiAttempt = strLinkId.TryConvertTo<Udi>();
|
||||
if (udiAttempt.Success)
|
||||
{
|
||||
var content = udiAttempt.Result.ToPublishedContent();
|
||||
if (content != null)
|
||||
{
|
||||
relatedLink.Id = content.Id;
|
||||
relatedLink = CreateLink(relatedLink);
|
||||
relatedLink.Content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (relatedLink.IsDeleted == false)
|
||||
{
|
||||
relatedLinks.Add(relatedLink);
|
||||
|
||||
Reference in New Issue
Block a user