Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds converter for Upload field #19

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<Compile Include="MediaPickerPropertyConverter.cs" />
<Compile Include="MultiNodeTreePickerPropertyConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UploadPropertyConverter.cs" />
<Compile Include="Utilities\ConverterHelper.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
101 changes: 101 additions & 0 deletions Our.Umbraco.PropertyConverters/UploadPropertyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Our.Umbraco.PropertyConverters.Utilities;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;

namespace Our.Umbraco.PropertyConverters
{
/// <summary>
/// The upload property value converter.
/// </summary>
public class UploadPropertyConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
{
/// <summary>
/// Checks if this converter can convert the property editor and registers if it can.
/// </summary>
/// <param name="propertyType">
/// The published property type.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public override bool IsConverter(PublishedPropertyType propertyType)
{
return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.UploadFieldAlias);
}

/// <summary>
/// The CLR type that the value converter returns.
/// </summary>
/// <param name="propertyType">
/// The property type.
/// </param>
/// <returns>
/// The <see cref="Type"/>.
/// </returns>
public Type GetPropertyValueType(PublishedPropertyType propertyType)
{
return typeof(string);
}

/// <summary>
/// Convert the source object to a string
/// </summary>
/// <param name="propertyType">
/// The published property type.
/// </param>
/// <param name="source">
/// The value of the property
/// </param>
/// <param name="preview">
/// The preview.
/// </param>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
{
return (source ?? "").ToString();
}

/// <summary>
/// The get property cache level.
/// </summary>
/// <param name="propertyType">
/// The property type.
/// </param>
/// <param name="cacheValue">
/// The cache value.
/// </param>
/// <returns>
/// The <see cref="PropertyCacheLevel"/>.
/// </returns>
public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, PropertyCacheValue cacheValue)
{
PropertyCacheLevel returnLevel;
switch (cacheValue)
{
case PropertyCacheValue.Object:
returnLevel = ConverterHelper.ModeFixed() ? PropertyCacheLevel.ContentCache : PropertyCacheLevel.Request;
break;
case PropertyCacheValue.Source:
returnLevel = PropertyCacheLevel.Content;
break;
case PropertyCacheValue.XPath:
returnLevel = PropertyCacheLevel.Content;
break;
default:
returnLevel = PropertyCacheLevel.None;
break;
}

return returnLevel;
}

}
}