Maybe this will help you. This is a custom condition for checking if the current page has a certain composition. I use this to display a workspace view or not. It’s not exactly what you need, but very close. (also the composition alias is hardcoded in this example):
import {
UmbConditionConfigBase,
UmbConditionControllerArguments,
UmbExtensionCondition
} from '@umbraco-cms/backoffice/extension-api';
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content';
/**
* Configuration for the ContentExpirationCondition
*/
export type ContentExpirationConditionConfig = UmbConditionConfigBase<'Pn.Condition.ContentExpiration'> & {
match?: string;
};
/**
* Represents an Umbraco condition that checks if the current content implements the content expiration composition
*/
export class ContentExpirationCondition extends UmbConditionBase<ContentExpirationConditionConfig> implements UmbExtensionCondition {
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<ContentExpirationConditionConfig>) {
super(host, args);
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (instance) => {
if (!instance)
return;
this.observe(instance.structure.contentTypeAliases, (aliases) => {
if (aliases.includes('expiringContent')) {
this.permitted = true;
} else {
this.permitted = false;
}
});
});
}
}
// Declare the Condition Configuration Type in the global UmbExtensionConditionConfigMap interface:
declare global {
interface UmbExtensionConditionConfigMap {
ContentExpirationConditionConfig: ContentExpirationConditionConfig;
}
}
You cannot use Workspace Conditions outside a Workspace, hence the name UMB_WORKSPACE_.
In this case the Alias is not available in the tree, so you need to use the GUID/unique of the Document Type.
And then I realized that particular Condition has not been made, and the right contexts for it to work universal is neither in place. so I have written a task to get it done in near future.
What you can do now, is to bring your own condition, and I wrote this code, which, with a bit of work, can be transformed into your own custom condition that should work in existing versions:
Because the UMB_TREE_ITEM_CONTEXT does hold an observable with the typeUnique when it’s a Document. But this would only work in the Document Tree, and the correct types and Context Token are missing at this stage, so this is a bit of a stretch, but an opportunity.