Limit entity action to specific document types

I am trying to add an entity action, but only for specific document types.

This is my manifest:

import { UMB_DOCUMENT_ENTITY_TYPE } from "@umbraco-cms/backoffice/document";
import { UMB_ENTITY_TYPE_CONDITION_ALIAS } from "@umbraco-cms/backoffice/entity";
import { ManifestEntityAction } from "@umbraco-cms/backoffice/entity-action";

export const manifests: Array<ManifestEntityAction> = [
    {
        alias: "ExpenseTypes.ExportExpenseTypesEntityAction",
        name: "Expense Types - Export Expense Types Entity Action",
        type: "entityAction",
        kind: "default",
        weight: 1000,
        api: () => import("./export-expense-types-entity-action.js"),
        forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
        meta: {
            icon: "icon-download-alt",
            label: "Export Expense Types",
        },
        conditions: [
           {
               alias: UMB_ENTITY_TYPE_CONDITION_ALIAS,
               match: "expenseTypeArchive",
           }
        ]

    }
];

But it doesn’t show. If I remove the condition, it shows - but for all content types.

I guess my alias is wrong, but what should it be then?

@skttl Try the UMB_WORKSPACE_CONTENT_TYPE_ALIAS_CONDITION_ALIAS condition alias.

No luck :frowning:

Is there a way I can put a breakpoint at where it selects the possible actions, maybe I can find available conditions there?

I also tried creating a custom condition, but I cant figure out how to get the current menu item from there…

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;
	}
}

Warren supplied with this elsewhere.

And I can see UMB_WORKSPACE_CONTENT_TYPE_ALIAS_CONDITION_ALIAS actually works when opening the workspace entity actions (top right corner).

I think that will work for me!

But, if others know how to get it in the tree, that would be awesome!

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.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.