Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 32390f6

Browse files
authored
Bugfix: Prevent delete a template when has children (#2479)
* Adds "Template Has No Children Condition" to prevent the "delete" action being displayed for templates that have child templates. * Removed condition config type it didn't have any configurable properties. Lazy-loaded the manifest api. * Renamed "Template Has No Children" condition to "Template Allow Delete Action" condition.
1 parent dbc373c commit 32390f6

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS = 'Umb.Condition.Template.AllowDeleteAction';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from './const.js';
2+
3+
export const manifest: UmbExtensionManifest = {
4+
type: 'condition',
5+
name: 'Template Allow Delete Action Condition',
6+
alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS,
7+
api: () => import('./template-allow-delete-action.condition.js'),
8+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
2+
import { UMB_TREE_ITEM_CONTEXT } from '@umbraco-cms/backoffice/tree';
3+
import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api';
4+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
5+
6+
export class UmbTemplateAllowDeleteActionCondition extends UmbConditionBase<never> implements UmbExtensionCondition {
7+
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<never>) {
8+
super(host, args);
9+
10+
this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => {
11+
this.observe(
12+
context.hasChildren,
13+
(hasChildren) => {
14+
this.permitted = hasChildren === false;
15+
},
16+
'_templateAllowDeleteActionCondition',
17+
);
18+
});
19+
}
20+
}
21+
22+
export { UmbTemplateAllowDeleteActionCondition as api };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { manifest as templateAllowDeleteActionCondition } from './allow-delete/manifest.js';
2+
3+
export const manifests: Array<UmbExtensionManifest> = [templateAllowDeleteActionCondition];

src/packages/templating/templates/entity-actions/manifests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS, UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
22
import { UMB_TEMPLATE_ENTITY_TYPE, UMB_TEMPLATE_ROOT_ENTITY_TYPE } from '../entity.js';
3+
import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from '../conditions/allow-delete/const.js';
34

45
export const manifests: Array<UmbExtensionManifest> = [
56
{
@@ -26,5 +27,6 @@ export const manifests: Array<UmbExtensionManifest> = [
2627
detailRepositoryAlias: UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS,
2728
itemRepositoryAlias: UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS,
2829
},
30+
conditions: [{ alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS }],
2931
},
3032
];

src/packages/templating/templates/manifests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { manifests as conditionsManifests } from './conditions/manifests.js';
12
import { manifests as entityActionsManifests } from './entity-actions/manifests.js';
23
import { manifests as menuManifests } from './menu/manifests.js';
34
import { manifests as modalManifests } from './modals/manifests.js';
@@ -7,6 +8,7 @@ import { manifests as treeManifests } from './tree/manifests.js';
78
import { manifests as workspaceManifests } from './workspace/manifests.js';
89

910
export const manifests: Array<UmbExtensionManifest> = [
11+
...conditionsManifests,
1012
...entityActionsManifests,
1113
...menuManifests,
1214
...modalManifests,

0 commit comments

Comments
 (0)