@@ -19,7 +19,6 @@ import { UmbDocumentValidationRepository } from '../repository/validation/index.
1919import { UMB_DOCUMENT_CONFIGURATION_CONTEXT } from '../index.js' ;
2020import { UMB_DOCUMENT_DETAIL_MODEL_VARIANT_SCAFFOLD , UMB_DOCUMENT_WORKSPACE_ALIAS } from './constants.js' ;
2121import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry' ;
22- import { ensurePathEndsWithSlash } from '@umbraco-cms/backoffice/utils' ;
2322import { observeMultiple } from '@umbraco-cms/backoffice/observable-api' ;
2423import { UmbContentDetailWorkspaceContextBase } from '@umbraco-cms/backoffice/content' ;
2524import { UmbDocumentBlueprintDetailRepository } from '@umbraco-cms/backoffice/document-blueprint' ;
@@ -29,7 +28,6 @@ import {
2928 UmbWorkspaceIsNewRedirectController ,
3029 UmbWorkspaceIsNewRedirectControllerAlias ,
3130} from '@umbraco-cms/backoffice/workspace' ;
32- import { UMB_SERVER_CONTEXT } from '@umbraco-cms/backoffice/server' ;
3331import type { UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content' ;
3432import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api' ;
3533import type { UmbDocumentTypeDetailModel } from '@umbraco-cms/backoffice/document-type' ;
@@ -276,11 +274,13 @@ export class UmbDocumentWorkspaceContext
276274 await super . _handleSave ( ) ;
277275 }
278276
279- public async saveAndPreview ( ) : Promise < void > {
280- return await this . #handleSaveAndPreview( ) ;
277+ public async saveAndPreview ( urlProviderAlias ?: string ) : Promise < void > {
278+ return await this . #handleSaveAndPreview( urlProviderAlias ?? 'umbDocumentUrlProvider' ) ;
281279 }
282280
283- async #handleSaveAndPreview( ) {
281+ async #handleSaveAndPreview( urlProviderAlias : string ) {
282+ if ( ! urlProviderAlias ) throw new Error ( 'Url provider alias is missing' ) ;
283+
284284 const unique = this . getUnique ( ) ;
285285 if ( ! unique ) throw new Error ( 'Unique is missing' ) ;
286286
@@ -296,28 +296,21 @@ export class UmbDocumentWorkspaceContext
296296 await this . performCreateOrUpdate ( variantIds , saveData ) ;
297297 }
298298
299- // Tell the server that we're entering preview mode.
300- await new UmbDocumentPreviewRepository ( this ) . enter ( ) ;
301-
302- const serverContext = await this . getContext ( UMB_SERVER_CONTEXT ) ;
303- if ( ! serverContext ) {
304- throw new Error ( 'Server context is missing' ) ;
305- }
306-
307- const backofficePath = serverContext . getBackofficePath ( ) ;
308- const previewUrl = new URL ( ensurePathEndsWithSlash ( backofficePath ) + 'preview' , window . location . origin ) ;
309- previewUrl . searchParams . set ( 'id' , unique ) ;
299+ // Get the preview URL from the server.
300+ const previewRepository = new UmbDocumentPreviewRepository ( this ) ;
301+ const previewUrlData = await previewRepository . getPreviewUrl (
302+ unique ,
303+ urlProviderAlias ,
304+ firstVariantId . culture ?? undefined ,
305+ firstVariantId . segment ?? undefined ,
306+ ) ;
310307
311- if ( firstVariantId . culture ) {
312- previewUrl . searchParams . set ( 'culture' , firstVariantId . culture ) ;
313- }
308+ // TODO: [LK] Interogate `previewUrlData.message` for any errors.
314309
315- if ( firstVariantId . segment ) {
316- previewUrl . searchParams . set ( 'segment' , firstVariantId . segment ) ;
310+ if ( previewUrlData . url ) {
311+ const previewWindow = window . open ( previewUrlData . url , `umbpreview-${ unique } ` ) ;
312+ previewWindow ?. focus ( ) ;
317313 }
318-
319- const previewWindow = window . open ( previewUrl . toString ( ) , `umbpreview-${ unique } ` ) ;
320- previewWindow ?. focus ( ) ;
321314 }
322315
323316 public createPropertyDatasetContext (
0 commit comments