Skip to content
Merged
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
1 change: 1 addition & 0 deletions samples/UmbracoV16/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.AddWebsite()
.AddComposers()
.AddRelewise(options => options
.AddContentType("homePage", contentType => contentType.AutoMap())
.AddContentType("contentPage", contentType => contentType.AutoMap()))
.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Relewise.Client.DataTypes;
using Relewise.Integrations.Umbraco.Infrastructure.Extensions;
using Relewise.Integrations.Umbraco.Services;
using Umbraco.Cms.Core.Models.Blocks;

namespace Relewise.Integrations.Umbraco.PropertyValueConverters;

internal class BlockListPropertyValueConverter(IServiceProvider serviceProvider) : IRelewisePropertyValueConverter
{
public bool CanHandle(RelewisePropertyConverterContext context)
{
return context.Property.PropertyType.EditorAlias.Equals("Umbraco.BlockList");
}

public void Convert(RelewisePropertyConverterContext context)
{
BlockListModel? blockList = context.Property.GetValue<BlockListModel>(context.Culture);

if (blockList != null)
{
// NOTE: This needs to be resolved manually, since it would cause a circular dependency if injected through constructor
var propertyConverter = serviceProvider.GetRequiredService<IRelewisePropertyConverter>();

var properties = new List<DataValue?>();

foreach (BlockListItem blockItem in blockList)
{
IReadOnlyDictionary<string, DataValue?> converted = propertyConverter.Convert(blockItem.Content.Properties, context.Culture);

properties.AddRange(converted.Values);
}

if (properties.Count == 0)
return;

string[] stringCollection = properties
.Select(x => x?.Value?.ToString())
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x!)
.ToArray();

context.Add(context.Property.Alias, new DataValue(stringCollection));
}
}
}
3 changes: 2 additions & 1 deletion src/Integrations.Umbraco/UmbracoBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public static IUmbracoBuilder AddRelewise(this IUmbracoBuilder builder, Action<R
.AddValueConverter<IntegerPropertyValueConverter>()
.AddValueConverter<DecimalPropertyValueConverter>()
.AddValueConverter<TagsPropertyValueConverter>()
.AddValueConverter<NestedContentPropertyValueConverter>();
.AddValueConverter<NestedContentPropertyValueConverter>()
.AddValueConverter<BlockListPropertyValueConverter>();

builder.AddNotificationAsyncHandler<ContentPublishedNotification, RelewiseContentPublishedNotificationHandler>();
builder.AddNotificationAsyncHandler<ContentUnpublishedNotification, RelewiseContentUnpublishedNotificationHandler>();
Expand Down