How to limit actions to specific doctypes

Hi,
I’m doing some custom actions where I select a specific content item in the backoffice and then I have a custom modal that pops out. All works well but I’d like to find a way to limit when this action is available. e.g.

if I right click a node and it’s not of type “FAQPage” and/or it’s parent isn’t “AboutUsPage” then don’t display the action button “Copy to Locations”

I started going down the route of

async isApplicable(): Promise<boolean> {
	if (this.args.entityType !== UMB_DOCUMENT_ENTITY_TYPE || !this.args.unique) return false;

	

	// Check if the parent's contentType alias is "locationParent"
	return true;
}

But that doesn’t let me check the selected doctype - from my understanding.

What you need is a custom condition. Each extension in the backoffice can have one or more conditions attached to it. And a menu item is also just an extension.

I made a condition for instance where I only want to show a workspace view if the entity is in the document workspace view (don’t want it in the media section for instance) and has a certain composition attached to it.

Or based on some custom logic, remove the delete button on certain nodes.

1 Like

Thanks @LuukPeters that was really useful. I’ve now got a custom condition setup - following the docs, but I still cant see how I can check the docType of the content item or find a way to check what the parent is of that node.
Do I need to make a request to a custom API endpoint to then do something to find the parent node etc or is there a way to do all that within typescript and the condition?

Because my condition is pretty small, I can share it with you. I think it does exactly what you want. The contentTypeAliases also contain the aliases of compositions and in my case that’s what I needed.

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) => {
			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;
	}
}

Thanks, this is getting me a bit closer. Just need to see if I can find a settings / option to find what parent it has.

From the top of my head, the parent unique can also be accessed by the content workspace context.