From 9ee45f098eea1336195e0a2410012134f4fa6245 Mon Sep 17 00:00:00 2001 From: Niklas Limberg Date: Fri, 4 Aug 2023 15:14:42 +0200 Subject: [PATCH] NEXT-25102 - Multiple CMS elements registered via Shopware 6 Admin SDK share same element config data --- src/ui/cms/index.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ui/cms/index.ts b/src/ui/cms/index.ts index 03e4a164..9be5e41a 100644 --- a/src/ui/cms/index.ts +++ b/src/ui/cms/index.ts @@ -1,7 +1,5 @@ import { createSender } from '../../channel'; -export const registerCmsElement = createSender('cmsRegisterElement'); - export type cmsRegisterElement = { responseType: void, @@ -28,3 +26,26 @@ export type cmsRegisterElement = { [key: string]: unknown, }, }; + +export const registerCmsElement = createSender('cmsRegisterElement'); + +export const isCmsLocation = (name: string, type: 'preview' | 'component' | 'config'): { isLocation: false } | {isLocation: true, dataSetId: string} => { + const params = new URLSearchParams(window.location.search); + + const locationId = params.get('location-id'); + if (!locationId) { + return { isLocation: false }; + } + + const locationParts = locationId.split('-'); + + const [elementName, elementType, id] = locationParts; + if (elementName !== name || elementType !== type || !id) { + return { isLocation: false }; + } + + return { + isLocation: true, + dataSetId: `${elementName}__${type}-${id}`, + }; +};