Having tried many options while scouring the Umbraco documentation and source code, it has not been clear to me how one would limit where a workspace is shown, based on the template type.
This is basically what I'm trying to do, it can be seen that the "Status" workspace is only shown on a specific page.
Ideally, what I tried to do first should be possible.
I have the umbraco-package.json, which contains something like the following:
Now the match and cast might not be correct, that doesn't really matter though, because there's a problem in condition.ts it throws an error in the constructor, when calling super().
export class MyExtensionCondition extends UmbControllerBase implements UmbExtensionCondition {
// ...
constructor(args: UmbConditionControllerArguments<MyConditionConfig>) {
console.log('calling super with host', args.host);
super(args.host);
console.log('Hello World!');
// ....
}
Then it prints:
calling super with host undefined
Uncaught (in promise) TypeError: this._host is undefined
And it never reaches the rest of the method.
Ideally, to limit where the workspace is shown, a simple regular condition should be available. I'd like to use the document template type, or to check whether it's a child of a content node, based on an alias or ID. But my superior, colleagues and I are all at a loss of what to do.
After 10 seconds the workspace becomes visible. So now I am able to create other custom checks, to set the permission for the Workspace to be shown. Such as using match together with a specific document type ID.
Here is my actual code to make the workspace visible for a certain document type:
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/document';
// ...
export type MyConditionDocumentTypeConfig = UmbConditionConfigBase & {
match: string;
};
export class MyExtensionCondition extends UmbConditionBase<MyConditionDocumentTypeConfig> implements UmbExtensionCondition {
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<MyConditionDocumentTypeConfig>) {
super(host, args);
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => {
// ideally i'd like to use the document type alias instead
this.permitted = (args.config.match === context.getContentTypeId());
})
}
}
export const manifest: ManifestCondition = {
type: 'condition',
name: 'My Condition',
alias: 'My.Condition.DocumentType',
api: MyExtensionCondition,
};
Hi, there is actually a workspace condition that should let you do exactly this based on the content type alias in Umb.Condition.WorkspaceContentTypeAlias
Ah yeah, you had me worried for a second that I missed something really obvious. During my search for this functionality I stumbled upon a GitHub discussion which links to some Discord messages, related to exactly that.
Limit workspace to document type
Having tried many options while scouring the Umbraco documentation and source code, it has not been clear to me how one would limit where a workspace is shown, based on the template type.
This is basically what I'm trying to do, it can be seen that the "Status" workspace is only shown on a specific page.
Ideally, what I tried to do first should be possible. I have the
umbraco-package.json
, which contains something like the following:And then I have a
workspace.ts
which looks like so:Now, the code above works, I can change the title and so on, but then comes the fun part. Registering my own condition. To do this I used some code from https://blog.hackmakedo.com/tag/umbraco-14/page/3/, but that didn't really work out. So I used the official Umbraco documentation https://docs.umbraco.com/umbraco-cms/extending/extending-overview/extension-types/condition
So my
workspace.ts
ends up looking like:Now the match and cast might not be correct, that doesn't really matter though, because there's a problem in
condition.ts
it throws an error in the constructor, when callingsuper()
.Then it prints:
And it never reaches the rest of the method.
Ideally, to limit where the workspace is shown, a simple regular condition should be available. I'd like to use the document template type, or to check whether it's a child of a content node, based on an alias or ID. But my superior, colleagues and I are all at a loss of what to do.
I had to change a bunch of things, which weren't in accordance with the documentation. I've created a pull request here: https://github.com/umbraco/UmbracoDocs/pull/6361
Instead of importing
UmbControllerBase
I had to importUmbConditionBase
, along with a bunch of other changes.My code ended up looking like the following:
Then my config file ended up looking like so:
After 10 seconds the workspace becomes visible. So now I am able to create other custom checks, to set the permission for the Workspace to be shown. Such as using
match
together with a specific document type ID.Here is my actual code to make the workspace visible for a certain document type:
Now the conditions look like so:
Hi, there is actually a workspace condition that should let you do exactly this based on the content type alias in
Umb.Condition.WorkspaceContentTypeAlias
You can see an example of it in the backoffice source code.
EDIT: This has been added since the v14.2 release, which means it'll be in v14.3 at the earliest (Thursday 3rd October release date I think)
Ah yeah, you had me worried for a second that I missed something really obvious. During my search for this functionality I stumbled upon a GitHub discussion which links to some Discord messages, related to exactly that.
https://github.com/umbraco/Umbraco-CMS/discussions/16683
I should probably have saved it and included it in my initial post.
Looking forward to the new condition though, it would definitely have saved me some time.
is working on a reply...