Skip to content

Commit 9fa2302

Browse files
committed
Get URL for media content types
1 parent 0f4491a commit 9fa2302

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/Constants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ public static class EntityType
4242

4343
public const int Form = 2;
4444
}
45+
46+
public static class MediaAliases
47+
{
48+
public const string UmbracoMediaPicker = "Umbraco.MediaPicker";
49+
50+
public const string UmbracoMediaPicker3 = "Umbraco.MediaPicker3";
51+
}
4552
}
4653
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Extensions/ContentExtensions.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#if NETCOREAPP
66
using Umbraco.Cms.Core.Models;
77
using Umbraco.Cms.Core.Models.PublishedContent;
8+
using Umbraco.Extensions;
89
#else
910
using Umbraco.Core.Models;
1011
using Umbraco.Core.Models.PublishedContent;
@@ -33,7 +34,10 @@ public static Dictionary<string, string> ToContentTypeDictionary(this IContentTy
3334

3435
var contentProperty = content.Properties.First(p => p.Alias == propertyType.Alias);
3536

36-
contentDict.Add(propertyType.Alias, contentProperty.GetValue().ToString());
37+
if(IsMedia(contentProperty, out string url))
38+
contentDict.Add(propertyType.Alias, url);
39+
else
40+
contentDict.Add(propertyType.Alias, contentProperty.GetValue().ToString());
3741
}
3842

3943
return contentDict;
@@ -55,5 +59,27 @@ public static Dictionary<string, string> ToContentDictionary(this IContent conte
5559

5660
return contentDict;
5761
}
62+
63+
private static bool IsMedia(IPublishedProperty contentProperty, out string url)
64+
{
65+
switch(contentProperty.PropertyType.EditorAlias)
66+
{
67+
case Constants.MediaAliases.UmbracoMediaPicker:
68+
var mediaPickerValue = contentProperty.GetValue() as IPublishedContent;
69+
#if NETCOREAPP
70+
url = mediaPickerValue.Url();
71+
#else
72+
url = mediaPickerValue.Url;
73+
#endif
74+
return true;
75+
case Constants.MediaAliases.UmbracoMediaPicker3:
76+
var mediaPicker3Value = contentProperty.GetValue() as MediaWithCrops;
77+
url = mediaPicker3Value.LocalCrops.Src;
78+
return true;
79+
default:
80+
url = string.Empty;
81+
return false;
82+
}
83+
}
5884
}
5985
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Umbraco.Cms.Integrations.Automation.Zapier.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
1717
<PackageReference Include="UmbracoCms.Web" Version="8.5.4" />
18+
<PackageReference Include="UmbracoCms.Core" Version="8.14.1" />
1819
</ItemGroup>
1920

2021
<ItemGroup Condition="'$(TargetFramework)' == 'net50'">

0 commit comments

Comments
 (0)