File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
src/Umbraco.Web.UI.Client/examples/workspace-context-initial-name Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # Workspace Context for setting an Initial Name
2+
3+ This example of a Workspace Context demonstrates how to manipulate the name of the workspaces entity.
Original file line number Diff line number Diff line change 1+ import {
2+ UMB_WORKSPACE_CONDITION_ALIAS ,
3+ UMB_WORKSPACE_ENTITY_IS_NEW_CONDITION_ALIAS ,
4+ } from '@umbraco-cms/backoffice/workspace' ;
5+
6+ export const manifests : Array < UmbExtensionManifest > = [
7+ {
8+ type : 'workspaceContext' ,
9+ name : 'Example Name Manipulation Workspace Context' ,
10+ alias : 'example.workspaceContext.nameManipulation' ,
11+ api : ( ) => import ( './workspace-context.js' ) ,
12+ conditions : [
13+ {
14+ alias : UMB_WORKSPACE_CONDITION_ALIAS ,
15+ match : 'Umb.Workspace.Document' ,
16+ } ,
17+ {
18+ alias : UMB_WORKSPACE_ENTITY_IS_NEW_CONDITION_ALIAS ,
19+ } ,
20+ ] ,
21+ } ,
22+ ] ;
Original file line number Diff line number Diff line change 1+ import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api' ;
2+ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api' ;
3+ import { UMB_CONTENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content' ;
4+ import { UmbVariantId } from '@umbraco-cms/backoffice/variant' ;
5+
6+ // The Example Workspace Context Controller:
7+ export class ExampleWorkspaceContextNameManipulation extends UmbControllerBase {
8+ constructor ( host : UmbControllerHost ) {
9+ super ( host ) ;
10+
11+ this . consumeContext ( UMB_CONTENT_WORKSPACE_CONTEXT , async ( workspace ) => {
12+ if ( ! workspace ) return ;
13+ await workspace . isLoaded ( ) ;
14+ // Set the name if it's already empty (We do not want to overwrite if it's a Blueprint)
15+ // Notice we need to provide a Variant-ID to getName, as Document names are variant specific. Here we get the Invariant name — this will need to be extended if you are looking to support multiple variants.
16+ const variantId = UmbVariantId . CreateInvariant ( ) ;
17+ const name = workspace . getName ( variantId ) ;
18+ if ( name === undefined ) {
19+ const manipulatedName = `New Document - ${ new Date ( ) . toLocaleDateString ( 'en-GB' ) } ` ;
20+ workspace . setName ( manipulatedName , variantId ) ;
21+ }
22+ } ) ;
23+ }
24+ }
25+
26+ // Declare a api export, so Extension Registry can initialize this class:
27+ export { ExampleWorkspaceContextNameManipulation as api } ;
You can’t perform that action at this time.
0 commit comments