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
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Models/Blocks/BlockEditorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private BlockEditorData()
/// <summary>
/// Returns the layout for this specific property editor
/// </summary>
public IEnumerable<TLayout>? Layout => BlockValue.Layout.TryGetValue(_propertyEditorAlias, out IEnumerable<TLayout>? layout) ? layout : null;
public IEnumerable<TLayout>? Layout => BlockValue.GetLayouts(_propertyEditorAlias);

/// <summary>
/// Returns the reference to the original BlockValue
Expand Down
21 changes: 11 additions & 10 deletions src/Umbraco.Core/Models/Blocks/BlockEditorDataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ public abstract class BlockEditorDataConverter<TValue, TLayout>
where TValue : BlockValue<TLayout>, new()
where TLayout : class, IBlockLayoutItem, new()
{
private readonly string _propertyEditorAlias;
private readonly IJsonSerializer _jsonSerializer;

[Obsolete("Use the constructor that takes IJsonSerializer. Will be removed in V15.")]
[Obsolete("Use the non-obsolete constructor. Will be removed in V15.")]
protected BlockEditorDataConverter(string propertyEditorAlias)
: this(propertyEditorAlias, StaticServiceProvider.Instance.GetRequiredService<IJsonSerializer>())
{
}

[Obsolete("Use the non-obsolete constructor. Will be removed in V15.")]
protected BlockEditorDataConverter(string propertyEditorAlias, IJsonSerializer jsonSerializer)
: this(jsonSerializer)
{
_propertyEditorAlias = propertyEditorAlias;
_jsonSerializer = jsonSerializer;
}

protected BlockEditorDataConverter(IJsonSerializer jsonSerializer)
=> _jsonSerializer = jsonSerializer;

public bool TryDeserialize(string json, [MaybeNullWhen(false)] out BlockEditorData<TValue, TLayout> blockEditorData)
{
try
Expand Down Expand Up @@ -60,16 +62,15 @@ public BlockEditorData<TValue, TLayout> Deserialize(string json)

public BlockEditorData<TValue, TLayout> Convert(TValue? value)
{
if (value?.Layout == null)
var propertyEditorAlias = new TValue().PropertyEditorAlias;
IEnumerable<TLayout>? layouts = value?.GetLayouts(propertyEditorAlias);
if (layouts is null)
{
return BlockEditorData<TValue, TLayout>.Empty;
}

IEnumerable<ContentAndSettingsReference> references =
value.Layout.TryGetValue(_propertyEditorAlias, out IEnumerable<TLayout>? layout)
? GetBlockReferences(layout)
: Enumerable.Empty<ContentAndSettingsReference>();
IEnumerable<ContentAndSettingsReference> references = GetBlockReferences(layouts);

return new BlockEditorData<TValue, TLayout>(_propertyEditorAlias, references, value);
return new BlockEditorData<TValue, TLayout>(propertyEditorAlias, references, value!);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BlockGridEditorDataConverter()
}

public BlockGridEditorDataConverter(IJsonSerializer jsonSerializer)
: base(Constants.PropertyEditors.Aliases.BlockGrid, jsonSerializer)
: base(jsonSerializer)
{
}

Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Core/Models/Blocks/BlockGridValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class BlockGridValue : BlockValue<BlockGridLayoutItem>
{
public override string PropertyEditorAlias => Constants.PropertyEditors.Aliases.BlockGrid;
}
1 change: 1 addition & 0 deletions src/Umbraco.Core/Models/Blocks/BlockListValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class BlockListValue : BlockValue<BlockListLayoutItem>
{
public override string PropertyEditorAlias => Constants.PropertyEditors.Aliases.BlockList;
}
15 changes: 13 additions & 2 deletions src/Umbraco.Core/Models/Blocks/BlockValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@

namespace Umbraco.Cms.Core.Models.Blocks;

public abstract class BlockValue<TLayout> where TLayout : IBlockLayoutItem
public abstract class BlockValue<TLayout> : BlockValue
where TLayout : IBlockLayoutItem
{
public IDictionary<string, IEnumerable<TLayout>> Layout { get; set; } = null!;
public IEnumerable<TLayout>? GetLayouts(string propertyEditorAlias)
=> Layout.TryGetValue(propertyEditorAlias, out IEnumerable<IBlockLayoutItem>? layouts) is true
? layouts.OfType<TLayout>()
: null;
}

public abstract class BlockValue
{
public IDictionary<string, IEnumerable<IBlockLayoutItem>> Layout { get; set; } = new Dictionary<string, IEnumerable<IBlockLayoutItem>>();

public List<BlockItemData> ContentData { get; set; } = new();

public List<BlockItemData> SettingsData { get; set; } = new();

public abstract string PropertyEditorAlias { get; }
}
1 change: 1 addition & 0 deletions src/Umbraco.Core/Models/Blocks/RichTextBlockValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ namespace Umbraco.Cms.Core.Models.Blocks;

public class RichTextBlockValue : BlockValue<RichTextBlockLayoutItem>
{
public override string PropertyEditorAlias => Constants.PropertyEditors.Aliases.TinyMce;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
namespace Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Serialization;

namespace Umbraco.Cms.Core.Models.Blocks;

/// <summary>
/// Data converter for blocks in the richtext property editor
/// </summary>
public sealed class RichTextEditorBlockDataConverter : BlockEditorDataConverter<RichTextBlockValue, RichTextBlockLayoutItem>
{
[Obsolete("Use the constructor that takes IJsonSerializer. Will be removed in V15.")]
public RichTextEditorBlockDataConverter()
: base(Constants.PropertyEditors.Aliases.TinyMce)
{
}

public RichTextEditorBlockDataConverter(IJsonSerializer jsonSerializer)
: base(jsonSerializer)
{
}

protected override IEnumerable<ContentAndSettingsReference> GetBlockReferences(IEnumerable<RichTextBlockLayoutItem> layout)
=> layout.Select(x => new ContentAndSettingsReference(x.ContentUdi, x.SettingsUdi)).ToList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Core.PropertyEditors;

Expand All @@ -23,16 +21,6 @@ public BlockValuePropertyIndexValueFactory(
{
}

[Obsolete("Use constructor that doesn't take IContentTypeService, scheduled for removal in V15")]
public BlockValuePropertyIndexValueFactory(
PropertyEditorCollection propertyEditorCollection,
IContentTypeService contentTypeService,
IJsonSerializer jsonSerializer,
IOptionsMonitor<IndexingSettings> indexingSettings)
: this(propertyEditorCollection, jsonSerializer, indexingSettings)
{
}

protected override IContentType? GetContentTypeOfNestedItem(BlockItemData input, IDictionary<Guid, IContentType> contentTypeDictionary)
=> contentTypeDictionary.TryGetValue(input.ContentTypeKey, out var result) ? result : null;

Expand All @@ -41,14 +29,9 @@ public BlockValuePropertyIndexValueFactory(

protected override IEnumerable<BlockItemData> GetDataItems(IndexValueFactoryBlockValue input) => input.ContentData;

internal class IndexValueFactoryBlockValue : BlockValue<IndexValueFactoryBlockLayoutItem>
// we only care about the content data when extracting values for indexing - not the layouts nor the settings
internal class IndexValueFactoryBlockValue
{
}

internal class IndexValueFactoryBlockLayoutItem : IBlockLayoutItem
{
public Udi? ContentUdi { get; set; }

public Udi? SettingsUdi { get; set; }
public List<BlockItemData> ContentData { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,6 @@ private RichTextEditorValue CleanAndMapBlocks(RichTextEditorValue richTextEditor
}

private BlockEditorValues<RichTextBlockValue, RichTextBlockLayoutItem> CreateBlockEditorValues()
=> new(new RichTextEditorBlockDataConverter(), _contentTypeService, _logger);
=> new(new RichTextEditorBlockDataConverter(_jsonSerializer), _contentTypeService, _logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
// See LICENSE for more details.

using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Serialization;

namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters;

internal class RichTextBlockPropertyValueCreator : BlockPropertyValueCreatorBase<RichTextBlockModel, RichTextBlockItem, RichTextBlockLayoutItem, RichTextConfiguration.RichTextBlockConfiguration, RichTextBlockValue>
{
private readonly IJsonSerializer _jsonSerializer;
private readonly RichTextBlockPropertyValueConstructorCache _constructorCache;

public RichTextBlockPropertyValueCreator(BlockEditorConverter blockEditorConverter, RichTextBlockPropertyValueConstructorCache constructorCache)
public RichTextBlockPropertyValueCreator(
BlockEditorConverter blockEditorConverter,
IJsonSerializer jsonSerializer,
RichTextBlockPropertyValueConstructorCache constructorCache)
: base(blockEditorConverter)
=> _constructorCache = constructorCache;
{
_jsonSerializer = jsonSerializer;
_constructorCache = constructorCache;
}

public RichTextBlockModel CreateBlockModel(PropertyCacheLevel referenceCacheLevel, RichTextBlockValue blockValue, bool preview, RichTextConfiguration.RichTextBlockConfiguration[] blockConfigurations)
{
Expand All @@ -24,7 +32,7 @@ public RichTextBlockModel CreateBlockModel(PropertyCacheLevel referenceCacheLeve
return blockModel;
}

protected override BlockEditorDataConverter<RichTextBlockValue, RichTextBlockLayoutItem> CreateBlockEditorDataConverter() => new RichTextEditorBlockDataConverter();
protected override BlockEditorDataConverter<RichTextBlockValue, RichTextBlockLayoutItem> CreateBlockEditorDataConverter() => new RichTextEditorBlockDataConverter(_jsonSerializer);

protected override BlockItemActivator<RichTextBlockItem> CreateBlockItemActivator() => new RichTextBlockItemActivator(BlockEditorConverter, _constructorCache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType)
return null;
}

var creator = new RichTextBlockPropertyValueCreator(_blockEditorConverter, _constructorCache);
var creator = new RichTextBlockPropertyValueCreator(_blockEditorConverter, _jsonSerializer, _constructorCache);
return creator.CreateBlockModel(referenceCacheLevel, blocks, preview, configuration.Blocks);
}

Expand Down
Loading