From bbfe40d733f1a175f0caf9d8419f3ed79eb2e920 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 3 Apr 2025 06:45:14 +0200 Subject: [PATCH] Fix issue preventing blueprint derived values from being scaffolded (#18917) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix issue preventing blueprint derived values from being scaffolded. * fix manipulating frooen array * compare with variantId as well --------- Co-authored-by: Niels Lyngsø --- .../content-detail-workspace-base.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content/workspace/content-detail-workspace-base.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content/workspace/content-detail-workspace-base.ts index da8ccb7b14..562b3c467a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content/workspace/content-detail-workspace-base.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content/workspace/content-detail-workspace-base.ts @@ -283,7 +283,7 @@ export abstract class UmbContentDetailWorkspaceContextBase< await this.structure.loadType((data as any)[this.#contentTypePropertyName].unique); // Set culture and segment for all values: - const cutlures = this.#languages.getValue().map((x) => x.unique); + const cultures = this.#languages.getValue().map((x) => x.unique); if (this.structure.variesBySegment) { console.warn('Segments are not yet implemented for preset'); @@ -319,11 +319,28 @@ export abstract class UmbContentDetailWorkspaceContextBase< ); const controller = new UmbPropertyValuePresetVariantBuilderController(this); - controller.setCultures(cutlures); + controller.setCultures(cultures); if (segments) { controller.setSegments(segments); } - data.values = await controller.create(valueDefinitions); + + const presetValues = await controller.create(valueDefinitions); + + // Don't just set the values, as we could have some already populated from a blueprint. + // If we have a value from both a blueprint and a preset, use the latter as priority. + const dataValues = [...data.values]; + for (let index = 0; index < presetValues.length; index++) { + const presetValue = presetValues[index]; + const variantId = UmbVariantId.Create(presetValue); + const matchingDataValueIndex = dataValues.findIndex((v) => v.alias === presetValue.alias && variantId.compare(v)); + if (matchingDataValueIndex > -1) { + dataValues[matchingDataValueIndex] = presetValue; + } else { + dataValues.push(presetValue); + } + } + + data.values = dataValues; return data; }