You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 15/umbraco-ui-builder/advanced/events.md
+40-32Lines changed: 40 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
---
2
-
description: Configuring event handlers in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2
+
description: Configuring event handlers in Umbraco UI Builder.
3
3
---
4
4
5
5
# Events
6
6
7
-
Umbraco UI Builder fires a number of notification events during regular operation to allow for extending of the default behaviour.
7
+
Umbraco UI Builder triggers different notification events during operation, allowing customization of default behavior.
8
8
9
-
## Registering event handlers
9
+
## Registering Event Handlers
10
10
11
-
Umbraco UI Builder uses the same [Notification Mechanism built into Umbraco v9+](../../umbraco-cms/fundamentals/code/subscribing-to-notifications.md) and so uses the same registration process. First you will need to define a notification event handler for the event you wish to handle like below:
11
+
Umbraco UI Builder follows the [Umbraco Notification mechanism](../../umbraco-cms/fundamentals/code/subscribing-to-notifications.md) for event registration.
12
+
13
+
Define a notification event handler for the target event:
Triggers when `Save` is called before persisting the entity. The notification contains an `Entity` property with `Before` and `After` values, providing access to the previous and updated entities. Modify the `After` entity to persist changes. If the `Cancel` property of the notification is set to `true` then the save operation will be canceled and no changes will be saved.
39
43
40
-
Raised when the repository `Save` method is called and before the entity has been persisted. The notification contains an `Entity` property with `Before` and `After` inner properties. These properties provide access to a copy of the currently persisted entity (or null if a new entity) and the updated entity that´s saved.
41
-
Changes can be made to the `After` entity and they will be persisted as part of the save operation. If the `Cancel` property of the notification is set to `true` then the save operation will be canceled and no changes will be saved.
Triggers when the repository `Save` method is called and after the entity has been persisted. The notification contains an `Entity` property with `Before` and `After` inner properties. These properties provide access to a copy of the previously persisted entity (or null if a new entity) and the updated entity that´s saved.
@@ -74,12 +77,13 @@ public class MyEntitySavedEventHandler : INotificationHandler<EntitySavedNotifi
74
77
}
75
78
```
76
79
77
-
### **EntityDeletingNotification**
80
+
### Using the `EntityDeletingNotification()`
81
+
82
+
Triggers when the repository `Delete` method is called and **before** the entity is deleted. The notification contains an `Entity` property providing access to a copy of the entity about to be deleted. If the `Cancel` property of notification is set to `true` then the delete operation will be cancelled and entity won't be deleted.
78
83
79
-
Raised when the repository `Delete` method is called and **before** the entity is deleted. The notification contains an `Entity` property providing access to a copy of the entity about to be deleted. If the `Cancel` property of notification is set to `true` then the delete operation will be cancelled and entity won't be deleted.
@@ -91,14 +95,15 @@ public class MyEntityDeletingEventHandler : INotificationHandler<EntityDeleting
91
95
}
92
96
93
97
}
94
-
````
98
+
```
99
+
100
+
### Using the `EntityDeletedNotification()`
95
101
96
-
### **EntityDeletedNotification**
102
+
Triggers when the repository `Delete` method is called and **after** the entity has been deleted. The notification contains an `Entity` property providing access to a copy of the entity that´s deleted.
97
103
98
-
Raised when the repository `Delete` method is called and **after** the entity has been deleted. The notification contains an `Entity` property providing access to a copy of the entity that´s deleted.
@@ -112,12 +117,13 @@ public class MyEntityDeletedEventHandler : INotificationHandler<EntityDeletedNo
112
117
}
113
118
```
114
119
115
-
### **SqlQueryBuildingNotification**
120
+
### Using the `SqlQueryBuildingNotification()`
116
121
117
-
Raised when the repository is **preparing** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object, and the where clause/order by clauses. These will be used to generate the SQL query.
122
+
Triggers when the repository is **preparing** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object, and the where clause/order by clauses. These will be used to generate the SQL query.
@@ -128,12 +134,13 @@ public class MySqlQueryBuildingEventHandler : INotificationHandler<SqlQueryBuil
128
134
}
129
135
```
130
136
131
-
### **SqlQueryBuiltNotification**
137
+
### Using the `SqlQueryBuiltNotification()`
138
+
139
+
Triggers when the repository has **repaired** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object and the where clause/order by clauses that was used to generate the SQL query.
132
140
133
-
Raised when the repository has **repaired** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object and the where clause/order by clauses that was used to generate the SQL query.
@@ -144,12 +151,13 @@ public class MySqlQueryBuiltEventHandler : INotificationHandler<SqlQueryBuiltNo
144
151
}
145
152
```
146
153
147
-
## Repository events validation
154
+
## Repository Events Validation
155
+
156
+
From version `15.1.0`, complex server-side validation can be added to a collection using the `CancelOperation` method of the notification.
148
157
149
-
Starting with version `15.1.0`, complex server-side validation can be added to a collection by calling the `CancelOperation` method of the notification.
Copy file name to clipboardExpand all lines: 15/umbraco-ui-builder/advanced/virtual-sub-trees.md
+47-26Lines changed: 47 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
description: Configuring virtual sub trees in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2
+
description: Configuring virtual sub trees in Umbraco UI Builder.
3
3
---
4
4
5
5
# Virtual SubTrees
@@ -8,52 +8,73 @@ description: Configuring virtual sub trees in Umbraco UI Builder, the backoffice
8
8
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
9
9
{% endhint %}
10
10
11
-
Virtual subtrees are a powerful feature that allows you to inject an Umbraco UI Builder tree structure into another Umbraco tree at a desired location. Thus acting as child nodes to the node chosen as the injection point. With virtual subtrees it allows you to extend builtin or even 3rd party package trees with additional features. An example could be developing a "loyalty point" program for your e-commerce site and injecting the related database tables into a Vendr store tree. This allows the management of the program in its most logical location.
11
+
Virtual subtrees inject an Umbraco UI Builder tree structure into another Umbraco tree at a specified location, acting as child nodes of the injection point. They extend built-in or third-party package trees with additional features. For example a "loyalty points" program for an e-commerce site can inject related database tables into a Commerce store tree, making management more intuitive.
12
12
13
-

13
+

14
14
15
-
## Defining virtual SubTrees
15
+
## Defining Virtual SubTrees
16
16
17
-
You define a virtual subtree by calling one of the `AddVirtualSubTree` methods of a [`WithTreeConfigBuilder`](../areas/trees.md#extending-an-existing-tree) instance.
17
+
Use the `AddVirtualSubTree` methods of a [WithTreeConfigBuilder](../areas/trees.md#extending-an-existing-tree) instance to define a virtual subtree.
Adds a virtual subtree to the current tree **before** the tree node matches the match expression, with its visibility controlled by the specified expression.
40
+
41
+
#### Method Syntax
31
42
32
-
Adds a virtual subtree to the current tree, **before** the tree node matches the match expression, with its visibility controlled via the visibility expression.
Adds a virtual subtree to the current tree **after** the tree node matches the match expression, with its visibility controlled by the specified expression.
Adds a virtual subtree to the current tree, **after** the tree node matches the match expression, with its visibility controlled via the visibility expression.
## Controlling where to inject the Virtual SubTrees
73
+
## Control the Virtual SubTrees Inject Location
53
74
54
-
Controlling where a virtual subtree is injected is done via the visibility expression passed to one of the `AddVirtualSubTree` methods on the root `UIBuilderConfigBuilder` instance. Without a visibility expression, Umbraco UI Builder would inject the virtual subtree under every node in the given tree. This expression can be used to identify the exact location where our tree should go.
75
+
Control the injection location by passing a visibility expression to the `AddVirtualSubTree` methods on the root `UIBuilderConfigBuilder` instance. Without a visibility expression, the subtree appears under every node in the target tree. This expression can be used to identify the exact location where the tree should go.
55
76
56
-
To help with this, the visibility expression is passed a single `VirtualSubTreeFilterContext` argument with relevant contextual information. This information is about the current node being rendered, alongside a list of the current user's user groups for permission-based visibility control. It also includes access to an `IServiceProvider`in case you need to resolve a service to determine the correct node to inject below.
77
+
The visibility expression receives a `VirtualSubTreeFilterContext` argument with relevant contextual information. The information includes the current node being rendered, alongside a list of the current user's user groups for permission-based visibility control. It also includes access to an `IServiceProvider`for dependency resolution.
57
78
58
79
````csharp
59
80
publicclassVirtualSubTreeFilterContext
@@ -72,7 +93,7 @@ public class NodeContext
72
93
}
73
94
````
74
95
75
-
Below you can find an example of a more complex filter expression where injection is based on the Document Type of a content node:
## Controlling the position of the injected Virtual SubTrees
113
+
## Control the Position of the injected Virtual SubTrees
93
114
94
-
The position of a virtual subtree within the child nodes of the injection node is controlled by using one of the `AddVirtualSubTreeBefore` or `AddVirtualSubTreeAfter` methods. These methods need to be on the root level `UIBuilderConfigBuilder` instance and pass a match expression used to identify the tree node to insert before/after. This expression is passed a single `TreeNode` argument to determine the position. It also requires a `boolean` return value to indicate the relevant location has been found.
115
+
The position of a virtual subtree within the child nodes of the injection node is controlled by using one of the `AddVirtualSubTreeBefore` or `AddVirtualSubTreeAfter` methods. These methods need to be on the root level `UIBuilderConfigBuilder` instance. The match expression identifies the node for insertion. This expression passes a single `TreeNode` argument to determine the position. It also requires a `boolean` return value to indicate the relevant location has been found.
95
116
96
117
````csharp
97
118
publicclassTreeNode
@@ -114,13 +135,13 @@ Below you can find an example of positioning a subtree after a node with the ali
114
135
treeNode=>treeNode.alias=="settings"
115
136
````
116
137
117
-
## Configuring a Virtual SubTrees
138
+
## Configuring a Virtual SubTree
118
139
119
-
VirtualsubtreessharethesameAPIasthe`Tree` configbuilderAPIincludingsupportforfoldersandcollections. Thereisanexception when adding collections to a subtree where you will have an additional foreign key expression parameter to define. The foreign key expression links the entities of the collection to the parent node of the subtree. For more information check the [Core Trees Documentation](../areas/trees.md).
140
+
Virtualsubtreesusethe `Tree` configbuilderAPIincludingsupportforfoldersandcollections. Thereisanexception when adding collections to a subtree where you will have an additional foreign key expression parameter to define. The foreign key expression links the entities of the collection to the parent node of the subtree. For more information, see the [Trees](../areas/trees.md) article.
120
141
121
-
## Injecting Virtual SubTrees into 3rd party trees
142
+
## Inject Virtual Subtrees into Third-Party Trees
122
143
123
-
Outofthebox, UmbracoUIBuildersupportsinjectingsubtreesintothecorecontent, media, members, andmembergrouptrees. Italsoincludes3rdpartysupportfor [Umbraco Commerce](../../umbraco-commerce/README.md) settingsandcommercetrees. Inordertosupportadditionaltreestoinjectinto, youmustimplementan `ITreeHelper` whichisusedtoextracttherequiredinformation. Thetreehelperconsistsofatreealiasforwhichthetreehelperis. Itincludesmethodstocorrectlyidentifythefullparentpath, auniqueIDfor a given node ID, and to resolve the actual entity ID. The entity ID should be used for the foreign key collection values.
144
+
Outofthebox, UmbracoUIBuildersupportsinjectingsubtreesintothecorecontent, media, members, andmembergrouptrees. Italsoincludesthird-partysupportfor [Umbraco Commerce](../../umbraco-commerce/README.md) settingsandcommercetrees. Toinjectintoadditionaltrees, implementan `ITreeHelper` toextractnecessarydata. Thetreehelperconsistsofatreealiasfor which the tree helper is. It includes methods to correctly identify the full parent path, a unique ID for a given node ID, and to resolve the actual entity ID. The entity ID should be used for the foreign key collection values.
124
145
125
146
````csharp
126
147
public interface ITreeHelper
@@ -132,10 +153,10 @@ public interface ITreeHelper
132
153
}
133
154
````
134
155
135
-
Once you have defined a tree helper, you can register the DI container in your startup class.
156
+
Once you have defined a tree helper, register the DI container in your startup class.
Once registered any virtual subtrees registered against the given helpers tree alias will then use your tree helper to locate the required information.
162
+
Once registered, any virtual subtree assigned to the helper’s tree alias will use it to locate required data.
0 commit comments