From ef0d2ae04e2641cdc8b041a9f95985b5aa62bd1e Mon Sep 17 00:00:00 2001 From: CodingDK Date: Fri, 16 Feb 2024 09:21:03 +0100 Subject: [PATCH] Prevent adding blocks that already added to the grid blocks --- .../Config/GridToBlockGridConfigBlockHelper.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uSync.Migrations.Migrators/BlockGrid/Config/GridToBlockGridConfigBlockHelper.cs b/uSync.Migrations.Migrators/BlockGrid/Config/GridToBlockGridConfigBlockHelper.cs index f88d207d..6cd29e90 100644 --- a/uSync.Migrations.Migrators/BlockGrid/Config/GridToBlockGridConfigBlockHelper.cs +++ b/uSync.Migrations.Migrators/BlockGrid/Config/GridToBlockGridConfigBlockHelper.cs @@ -129,7 +129,17 @@ private Dictionary AddGridContentBlocksToConfig(ILegacyGridEdito _logger.LogDebug("Adding {editor} to block config for {count} blocks", editor.Alias, blocks.Count); - gridBlockContext.ContentBlocks.AddRange(blocks); + var containingBlockKeys = gridBlockContext.ContentBlocks.Select(x => x.ContentElementTypeKey).ToArray(); + + foreach (var block in blocks) + { + if (containingBlockKeys.Contains(block.ContentElementTypeKey)) + { + _logger.LogDebug("Block ContentElementTypeKey {block} already exists in the config", block.ContentElementTypeKey); + continue; + } + gridBlockContext.ContentBlocks.Add(block); + } allowedContentTypes[editor.Alias!] = blocks.Select(x => x.ContentElementTypeKey).ToArray(); }