Skip to content

Commit 714ee4d

Browse files
committed
Updated articles
1 parent 27396bf commit 714ee4d

File tree

2 files changed

+87
-58
lines changed

2 files changed

+87
-58
lines changed

15/umbraco-ui-builder/advanced/events.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2-
description: Configuring event handlers in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2+
description: Configuring event handlers in Umbraco UI Builder.
33
---
44

55
# Events
66

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.
88

9-
## Registering event handlers
9+
## Registering Event Handlers
1010

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:
1214

1315
```csharp
1416
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
@@ -21,7 +23,7 @@ public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNoti
2123
}
2224
```
2325

24-
Then register your event handler in the `Program.cs` file like below:
26+
Register the event handler in `Program.cs`:
2527

2628
```csharp
2729
builder.CreateUmbracoBuilder()
@@ -33,15 +35,15 @@ builder.CreateUmbracoBuilder()
3335
.Build();
3436
```
3537

36-
## Repository events
38+
## Repository Events
39+
40+
### Using the `EntitySavingNotification()`
3741

38-
### **EntitySavingNotification**
42+
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.
3943

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.
44+
#### Example
4245

4346
```csharp
44-
// Example
4547
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
4648

4749
public void Handle(EntitySavingNotification notification)
@@ -53,14 +55,15 @@ public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNoti
5355
}
5456

5557
}
56-
````
58+
```
5759

58-
### **EntitySavedNotification**
60+
### Using the `EntitySavedNotification()`
5961

60-
Raised 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.
62+
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.
6163

62-
````csharp
63-
// Example
64+
#### Example
65+
66+
```csharp
6467
public class MyEntitySavedEventHandler : INotificationHandler<EntitySavedNotification> {
6568

6669
public void Handle(EntitySavedNotification notification)
@@ -74,12 +77,13 @@ public class MyEntitySavedEventHandler : INotificationHandler<EntitySavedNotifi
7477
}
7578
```
7679

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.
7883

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.
84+
#### Example
8085

81-
````csharp
82-
// Example
86+
```csharp
8387
public class MyEntityDeletingEventHandler : INotificationHandler<EntityDeletingNotification> {
8488

8589
public void Handle(EntityDeletingNotification notification)
@@ -91,14 +95,15 @@ public class MyEntityDeletingEventHandler : INotificationHandler<EntityDeleting
9195
}
9296

9397
}
94-
````
98+
```
99+
100+
### Using the `EntityDeletedNotification()`
95101

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.
97103

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.
104+
#### Example
99105

100106
```csharp
101-
// Example
102107
public class MyEntityDeletedEventHandler : INotificationHandler<EntityDeletedNotification> {
103108

104109
public void Handle(EntityDeletedNotification notification)
@@ -112,12 +117,13 @@ public class MyEntityDeletedEventHandler : INotificationHandler<EntityDeletedNo
112117
}
113118
```
114119

115-
### **SqlQueryBuildingNotification**
120+
### Using the `SqlQueryBuildingNotification()`
116121

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.
123+
124+
#### Example
118125

119126
```csharp
120-
// Example
121127
public class MySqlQueryBuildingEventHandler : INotificationHandler<SqlQueryBuildingNotification> {
122128

123129
public void Handle(SqlQueryBuildingNotification notification)
@@ -128,12 +134,13 @@ public class MySqlQueryBuildingEventHandler : INotificationHandler<SqlQueryBuil
128134
}
129135
```
130136

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.
132140

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.
141+
#### Example
134142

135143
```csharp
136-
// Example
137144
public class MySqlQueryBuiltEventHandler : INotificationHandler<SqlQueryBuiltNotification> {
138145

139146
public void Handle(SqlQueryBuiltNotification notification)
@@ -144,12 +151,13 @@ public class MySqlQueryBuiltEventHandler : INotificationHandler<SqlQueryBuiltNo
144151
}
145152
```
146153

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.
148157

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.
158+
### Example
150159

151160
```csharp
152-
// Example
153161
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
154162

155163
public void Handle(EntitySavingNotification notification)

15/umbraco-ui-builder/advanced/virtual-sub-trees.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
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.
33
---
44

55
# Virtual SubTrees
@@ -8,52 +8,73 @@ description: Configuring virtual sub trees in Umbraco UI Builder, the backoffice
88
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.
99
{% endhint %}
1010

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 built in 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.
1212

13-
![Example virtual sub tree injected into a Vendr store tree](../images/virtual-sub-tree.png)
13+
![Virtual sub tree injected into a Commerce store tree](../images/virtual-sub-tree.png)
1414

15-
## Defining virtual SubTrees
15+
## Defining Virtual SubTrees
1616

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.
1818

19-
### **AddVirtualSubTree(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder**
19+
### Using the `AddVirtualSubTree()` Method
2020

21-
Adds a virtual subtree to the current tree with its visibility controlled via the visibility expression.
21+
Adds a virtual subtree to the current tree with visibility controlled by the specified expression.
22+
23+
#### Method Syntax
24+
25+
```csharp
26+
AddVirtualSubTree(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder
27+
```
28+
29+
#### Example
2230

2331
````csharp
24-
// Example
2532
withTreeConfig.AddVirtualSubTree(ctx => ctx.Source.Id == 1056, contextAppConfig => {
2633
...
2734
});
2835
````
2936

30-
### **AddVirtualSubTreeBefore(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda matchExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder**
37+
### Using the `AddVirtualSubTreeBefore()` Method
38+
39+
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
3142

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.
43+
```csharp
44+
AddVirtualSubTreeBefore(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda matchExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder
45+
```
46+
47+
#### Example
3348

3449
````csharp
35-
// Example
3650
withTreeConfig.AddVirtualSubTreeBefore(ctx => ctx.Source.Id == 1056, treeNode => treeNode.Name == "Settings", contextAppConfig => {
3751
...
3852
});
3953
````
4054

41-
### **AddVirtualSubTreeAfter(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda matchExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder**
55+
### Using the `AddVirtualSubTreeAfter()` Method
56+
57+
Adds a virtual subtree to the current tree **after** the tree node matches the match expression, with its visibility controlled by the specified expression.
58+
59+
#### Method Syntax
60+
61+
```csharp
62+
AddVirtualSubTreeAfter(string sectionAlias, string treeAlias, Lambda visibilityExpression, Lambda matchExpression, Lambda virtualSubTreeConfig = null) : VirtualSubTreeConfigBuilder
63+
```
4264

43-
Adds a virtual subtree to the current tree, **after** the tree node matches the match expression, with its visibility controlled via the visibility expression.
65+
#### Example
4466

4567
````csharp
46-
// Example
4768
withTreeConfig.AddVirtualSubTreeAfter(ctx => ctx.Source.Id == 1056, treeNode => treeNode.Name == "Settings", contextAppConfig => {
4869
...
4970
});
5071
````
5172

52-
## Controlling where to inject the Virtual SubTrees
73+
## Control the Virtual SubTrees Inject Location
5374

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.
5576

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.
5778

5879
````csharp
5980
public class VirtualSubTreeFilterContext
@@ -72,7 +93,7 @@ public class NodeContext
7293
}
7394
````
7495

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:
96+
### Example: Filter Injection by Document Type
7697

7798
````csharp
7899
withTreeConfig.AddVirtualSubTree(ctx =>
@@ -89,9 +110,9 @@ withTreeConfig.AddVirtualSubTree(ctx =>
89110
);
90111
````
91112

92-
## Controlling the position of the injected Virtual SubTrees
113+
## Control the Position of the injected Virtual SubTrees
93114

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.
95116

96117
````csharp
97118
public class TreeNode
@@ -114,13 +135,13 @@ Below you can find an example of positioning a subtree after a node with the ali
114135
treeNode => treeNode.alias == "settings"
115136
````
116137

117-
## Configuring a Virtual SubTrees
138+
## Configuring a Virtual SubTree
118139

119-
Virtual subtrees share the same API as the `Tree` config builder API including support for folders and collections. There is an exception 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+
Virtual subtrees use the `Tree` config builder API including support for folders and collections. There is an exception 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.
120141

121-
## Injecting Virtual SubTrees into 3rd party trees
142+
## Inject Virtual Subtrees into Third-Party Trees
122143

123-
Out of the box, Umbraco UI Builder supports injecting subtrees into the core content, media, members, and member group trees. It also includes 3rd party support for [Umbraco Commerce](../../umbraco-commerce/README.md) settings and commerce trees. In order to support additional trees to inject into, you must implement an `ITreeHelper` which is used to extract the required information. The tree helper consists of a tree alias for 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.
144+
Out of the box, Umbraco UI Builder supports injecting subtrees into the core content, media, members, and member group trees. It also includes third-party support for [Umbraco Commerce](../../umbraco-commerce/README.md) settings and commerce trees. To inject into additional trees, implement an `ITreeHelper` to extract necessary data. The tree helper consists of a tree alias for 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.
124145

125146
````csharp
126147
public interface ITreeHelper
@@ -132,10 +153,10 @@ public interface ITreeHelper
132153
}
133154
````
134155

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.
136157

137158
````csharp
138159
builder.Services.AddSingleton<ITreeHelper, MyCustomTreeHelper>();
139160
````
140161

141-
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

Comments
 (0)