Remove existing menu item from certain content type

Hi, what would be correct way to hide or remove menu item for certain content type. For example remove “Trash” menu item from HomePage content type? Previously it was done via MenuRenderingNotification but I assume now it has to be done by extending frontend.

helloi @Marcis

yes you’re right, MenuRenderingNotification is gone. “Trash” is registered as an Entity Action with alias Umb.EntityAction.Document.RecycleBin.Trash, and it’s normally invoked from the tree context menu not from inside an open workspace.

There’s no built-in condition yet for “this tree item’s content type,” so you need a custom one. Umbraco’s own tree-item-type-unique condition is the closest existing pattern it reads typeUnique off UMB_TREE_ITEM_CONTEXT, which for a document is the document type’s GUID, not its alias:

// hide-trash-for-homepage.condition.ts
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
import { UMB_TREE_ITEM_CONTEXT } from '@umbraco-cms/backoffice/tree';
import type { UmbConditionConfigBase, UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';

export type HideTrashForHomePageConditionConfig =
    UmbConditionConfigBase<'My.Condition.HideTrashForHomePage'> & {
        match?: string;
    };

export class HideTrashForHomePageCondition
    extends UmbConditionBase<HideTrashForHomePageConditionConfig>
    implements UmbExtensionCondition
{
    constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<HideTrashForHomePageConditionConfig>) {
        super(host, args);

        this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => {
            this.observe((context as any)?.typeUnique, (typeUnique: string | undefined) => {
                // permitted = show the action, so invert the match:
                // hide (permitted = false) when typeUnique matches HomePage's doctype GUID
                this.permitted = typeUnique !== this.config.match;
            }, '_HideTrashForHomePageCondition');
        });
    }
}

export { HideTrashForHomePageCondition as api };

declare global {
    interface UmbExtensionConditionConfigMap {
        HideTrashForHomePageConditionConfig: HideTrashForHomePageConditionConfig;
    }
}

Register the condition, then attach it to the existing Trash action with appendCondition rather than overwriting it:

ts

// manifests.ts
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';

const HIDE_TRASH_FOR_HOMEPAGE_CONDITION_ALIAS = 'My.Condition.HideTrashForHomePage';

umbExtensionsRegistry.register({
    type: 'condition',
    name: 'Hide Trash For HomePage Condition',
    alias: HIDE_TRASH_FOR_HOMEPAGE_CONDITION_ALIAS,
    api: () => import('./hide-trash-for-homepage.condition.js'),
});

umbExtensionsRegistry.appendCondition('Umb.EntityAction.Document.RecycleBin.Trash', {
    alias: HIDE_TRASH_FOR_HOMEPAGE_CONDITION_ALIAS,
    match: 'YOUR-HOMEPAGE-DOCTYPE-GUID-HERE', // the doc type's key, not its alias
});

(Note: this reply was drafted with AI assistance and cross-checked against real Umbraco source/discussions, but I haven’t tested it against a live v17 instance so treat it as a strong starting point rather than copy-paste-guaranteed. Worth a sanity check in a dev environment before relying on it, especially the typeUnique / appendCondition timing bits.)

You can also use my package. It can do that. :slight_smile: in contrast to just a condition, this will also enforece it on the management api.