|
1 | 1 | --- |
2 | | -description: Configuring context apps in Umbraco UI Builder, the backoffice UI builder for Umbraco. |
| 2 | +description: Configuring context apps in Umbraco UI Builder. |
3 | 3 | --- |
4 | 4 |
|
5 | 5 | # Context Apps |
6 | 6 |
|
7 | | -Context Apps in Umbraco UI Builder are analogous to Content Apps in Umbraco. They allow you to provide contextual apps that appear in the editor UI of content. From Umbraco UI Builder's perspective, defining context apps allows you to expose collections as content apps. This is where a collection has a relation to the content in question. An example could be something like blog post comments which are linked to individual blog posts. Exposing these as a content app allows them to be managed in context next to the blog post they are linked to. |
| 7 | +Context Apps in Umbraco UI Builder function similarly to Content Apps. They provide contextual applications within the content editor UI. By defining context apps, you can expose collections that are directly related to the content in question. For example, blog post comments can be linked to their respective blog posts and managed in context through a content app. |
8 | 8 |
|
9 | 9 |  |
10 | 10 |
|
11 | | -## Defining a context app |
| 11 | +## Defining a Context App |
12 | 12 |
|
13 | 13 | You can define a context app by calling one of the `AddContextApp` methods on a [`WithTreeConfigBuilder`](trees.md#extending-an-existing-tree) instance. |
14 | 14 |
|
15 | | -### **AddContextApp(string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 15 | +### Using the `AddContextApp()` Method |
16 | 16 |
|
17 | | -Adds a context app with the given name and default icon. |
| 17 | +Adds a context app with the specified name and default icon. |
| 18 | + |
| 19 | +#### Method Syntax |
| 20 | + |
| 21 | +```cs |
| 22 | +AddContextApp(string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 23 | +``` |
| 24 | + |
| 25 | +#### Example |
18 | 26 |
|
19 | 27 | ```csharp |
20 | | -// Example |
21 | 28 | withTreeConfig.AddContextApp("Comments", contextAppConfig => { |
22 | 29 | ... |
23 | 30 | }); |
24 | 31 | ``` |
25 | 32 |
|
26 | | -### **AddContextApp(string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 33 | +### Using the `AddContextApp()` Method with Custom Icon |
| 34 | + |
| 35 | +Adds a context app with the specified name and custom icon. |
| 36 | + |
| 37 | +#### Method Syntax |
27 | 38 |
|
28 | | -Adds a context app to the Umbraco menu with the given name and icon. |
| 39 | +```cs |
| 40 | +AddContextApp(string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 41 | +``` |
| 42 | + |
| 43 | +#### Example |
29 | 44 |
|
30 | 45 | ```csharp |
31 | | -// Example |
32 | 46 | withTreeConfig.AddContextApp("Comments", "icon-chat", contextAppConfig => { |
33 | 47 | ... |
34 | 48 | }); |
35 | 49 | ``` |
36 | 50 |
|
37 | | -### **AddContextAppBefore(string beforeAlias, string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 51 | +### Using the `AddContextAppBefore()` Method |
| 52 | + |
| 53 | +Adds a context app with the specified name and default icon before another context app specified by its alias. |
| 54 | + |
| 55 | +#### Method Syntax |
| 56 | + |
| 57 | +```cs |
| 58 | +AddContextAppBefore(string beforeAlias, string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 59 | +``` |
38 | 60 |
|
39 | | -Adds a context app with the given name and default icon **before** the context app with the given alias. |
| 61 | +#### Example |
40 | 62 |
|
41 | 63 | ```csharp |
42 | | -// Example |
43 | 64 | withTreeConfig.AddContextAppBefore("umbContent", "Comments", contextAppConfig => { |
44 | 65 | ... |
45 | 66 | }); |
46 | 67 | ``` |
47 | 68 |
|
48 | | -### **AddContextAppBefore(string beforeAlias, string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 69 | +### Using the `AddContextAppBefore()` Method with a Custom Icon |
49 | 70 |
|
50 | | -Adds a context app to the Umbraco menu with the given name and icon **before** the context app with the given alias. |
| 71 | +Adds a context app with the specified name and custom icon before another context app specified by its alias. |
| 72 | + |
| 73 | +#### Method Syntax |
| 74 | + |
| 75 | +```cs |
| 76 | +AddContextAppBefore(string beforeAlias, string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 77 | +``` |
| 78 | + |
| 79 | +#### Example |
51 | 80 |
|
52 | 81 | ```csharp |
53 | | -// Example |
54 | 82 | withTreeConfig.AddContextAppBefore("umbContent", "Comments", "icon-chat", contextAppConfig => { |
55 | 83 | ... |
56 | 84 | }); |
57 | 85 | ``` |
58 | 86 |
|
59 | | -### **AddContextAppAfter(string afterAlias, string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 87 | +### Using the `AddContextAppAfter()` Method |
| 88 | + |
| 89 | +Adds a context app with the specified name and default icon after another context app specified by its alias. |
| 90 | + |
| 91 | +#### Method Syntax |
60 | 92 |
|
61 | | -Adds a context app with the given name and default icon **after** the context app with the given alias. |
| 93 | +```cs |
| 94 | +AddContextAppAfter(string afterAlias, string name, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 95 | +``` |
| 96 | + |
| 97 | +#### Example |
62 | 98 |
|
63 | 99 | ```csharp |
64 | | -// Example |
| 100 | + |
65 | 101 | withTreeConfig.AddContextAppAfter("umbContent", "Comments", contextAppConfig => { |
66 | 102 | ... |
67 | 103 | }); |
68 | 104 | ``` |
69 | 105 |
|
70 | | -### **AddContextAppAfter(string afterAlias, string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder** |
| 106 | +### Using the `AddContextAppAfter()` Method with a Custom Icon |
| 107 | + |
| 108 | +Adds a context app with the specified name and custom icon after another context app specified by its alias. |
| 109 | + |
| 110 | +#### Method Syntax |
| 111 | + |
| 112 | +```cs |
| 113 | +AddContextAppAfter(string afterAlias, string name, string icon, Lambda contextAppConfig = null) : ContextAppConfigBuilder |
| 114 | +``` |
71 | 115 |
|
72 | | -Adds a context app to the Umbraco menu with the given name and icon **after** the context app with the given alias. |
| 116 | +#### Example |
73 | 117 |
|
74 | 118 | ```csharp |
75 | | -// Example |
76 | 119 | withTreeConfig.AddContextAppAfter("umbContent", "Comments", "icon-chat", contextAppConfig => { |
77 | 120 | ... |
78 | 121 | }); |
79 | 122 | ``` |
80 | 123 |
|
81 | | -## Changing a context app alias |
| 124 | +## Changing a Context App Alias |
| 125 | + |
| 126 | +### Using the `SetAlias()` Method |
82 | 127 |
|
83 | | -### **SetAlias(string alias) : ContextAppConfigBuilder** |
| 128 | +Sets the alias of the context app. By default, an alias is automatically generated from the context app's name. You can use the `SetAlias` method to specify a custom alias. |
| 129 | + |
| 130 | +#### Method Syntax |
84 | 131 |
|
85 | | -Sets the alias of the context app. |
| 132 | +```cs |
| 133 | +SetAlias(string alias) : ContextAppConfigBuilder |
| 134 | +``` |
86 | 135 |
|
87 | | -**Optional:** When adding a new context app, an alias is automatically generated from the supplied name for you. However, you can use the `SetAlias` method to override this if you need a specific alias. |
| 136 | +#### Example |
88 | 137 |
|
89 | 138 | ```csharp |
90 | | -// Example |
91 | 139 | contextAppConfig.SetAlias("comments"); |
92 | 140 | ``` |
93 | 141 |
|
94 | | -## Changing a context app icon color |
| 142 | +## Changing a Context App Icon Color |
| 143 | + |
| 144 | +### Using the `SetIconColor()` Method |
| 145 | + |
| 146 | +Sets the context app icon color to the given color. The available colors are: `black`, `green`, `yellow`, `orange`, `blue` or `red`. |
| 147 | + |
| 148 | +#### Method Syntax |
95 | 149 |
|
96 | | -### **SetIconColor(string color) : ContextAppConfigBuilder** |
| 150 | +```cs |
| 151 | +SetIconColor(string color) : ContextAppConfigBuilder |
| 152 | +``` |
97 | 153 |
|
98 | | -Sets the context app icon color to the given color. Possible options are `black`, `green`, `yellow`, `orange`, `blue` or `red`. |
| 154 | +#### Example |
99 | 155 |
|
100 | 156 | ````csharp |
101 | | -// Example |
102 | 157 | contextAppConfig.SetIconColor("blue"); |
103 | 158 | ```` |
104 | 159 |
|
105 | | -## Changing when a context app should display |
| 160 | +## Changing Context App Visibility |
| 161 | + |
| 162 | +Context app visibility is controlled by a delegate that takes a `ContextAppVisibilityContext` instance. This method contains a `Source` property which holds a reference to the source object that the content app is being displayed on (i.e., an `IContent` instance). It also holds a reference to a `UserGroups` collection of the currently logged-in user's user groups. You can use these values to determine when the context app should be displayed. |
| 163 | + |
| 164 | +By default, context apps are pre-filtered to only appear on the tree they are defined in. This default behavior is combined with the SetVisibility configuration to control visibility. |
106 | 165 |
|
107 | | -Changing when a context app is displayed, is controlled by a delegate method which is passed a `ContextAppVisibilityContext` instance. This method contains a `Source` property which holds a reference to the source object that the content app is being displayed on (i.e., an `IContent` instance). It also holds a reference to a `UserGroups` collection of the currently logged-in user's user groups. You can use any value from those to return a boolean result which sets whether to display the context app or not. |
| 166 | +### Using the `SetIconColor()` Method |
108 | 167 |
|
109 | | -By default, Umbraco UI Builder will pre-filter context apps to only display on the tree it is defined in. This will be combined with the `SetVisibility` config to decide when to display the context app. |
| 168 | +Defines the visibility of the context app based on a delegate expression. |
110 | 169 |
|
111 | | -### **SetVisibility(Func<ContextAppVisibilityContext, bool> visibilityExpression) : ContextAppConfigBuilder** |
| 170 | +#### Method Syntax |
112 | 171 |
|
113 | | -Sets the context app visibility delegate. |
| 172 | +```cs |
| 173 | +SetVisibility(Func<ContextAppVisibilityContext, bool> visibilityExpression) : ContextAppConfigBuilder |
| 174 | +``` |
| 175 | + |
| 176 | +#### Example |
114 | 177 |
|
115 | 178 | ````csharp |
116 | | -// Example |
117 | 179 | contextAppConfig.SetVisibility(appCtx => appCtx.Source is IContent content && content.ContentType.Alias == "blogPost"); |
118 | 180 | ```` |
119 | 181 |
|
120 | | -## Adding a collection to a context app |
| 182 | +## Adding a Collection to a Context App |
121 | 183 |
|
122 | 184 | Context apps can consist of one or more collections. If a context app contains multiple collections, the collection list views will be displayed in tabs within the context app. |
123 | 185 |
|
124 | | -### **AddCollection<TEntityType>(Lambda idFieldExpression, Lambda fkFieldExpression, string nameSingular, string namePlural, string description, Lambda collectionConfig = null) : ContextAppConfigBuilder** |
| 186 | +### Using the `AddCollection<>()` Method |
| 187 | + |
| 188 | +Adds a collection to the current context app with the specified names, descriptions, and default icons. Each collection requires an ID field and a foreign key field, linking to Umbraco node UDI values. For more details, see the [Collections](../collections/overview.md) article. |
125 | 189 |
|
126 | | -Adds a collection to the current content app with the given names, descriptions and default icons. An ID property accessor expression is required so that Umbraco UI Builder knows which property is the ID property. A foreign key property accessor is also required so that the Umbraco UI Builder knows which property holds the Umbraco nodes UDI value. You can read more about this in the [Collections documentation](../collections/overview.md). |
| 190 | +#### Method Syntax |
| 191 | + |
| 192 | +```cs |
| 193 | +AddCollection<TEntityType>( |
| 194 | + Lambda idFieldExpression, |
| 195 | + Lambda fkFieldExpression, |
| 196 | + string nameSingular, |
| 197 | + string namePlural, |
| 198 | + string description, |
| 199 | + Lambda collectionConfig = null |
| 200 | +) : ContextAppConfigBuilder |
| 201 | +``` |
| 202 | + |
| 203 | +#### Example |
127 | 204 |
|
128 | 205 | ```csharp |
129 | | -// Example |
130 | | -contextAppConfig.AddCollection<Comment>(p => p.Id, p=> "Comment", "Comments", "A collection of comments", collectionConfig => { |
131 | | - ... |
132 | | -}); |
| 206 | +contextAppConfig.AddCollection<Comment>( |
| 207 | + p => p.Id, |
| 208 | + p => "Comment", |
| 209 | + "Comments", |
| 210 | + "A collection of comments", |
| 211 | + collectionConfig => { |
| 212 | + // Collection configuration here |
| 213 | + } |
| 214 | +); |
133 | 215 | ``` |
134 | 216 |
|
135 | | -### **AddCollection<TEntityType>(Lambda idFieldExpression, Lambda fkFieldExpression, string nameSingular, string namePlural, string description, string iconSingular, string iconPlural, Lambda collectionConfig = null) : ContextAppConfigBuilder** |
| 217 | +### Using the `AddCollection<>()` Method with Custom Icon |
| 218 | + |
| 219 | +**AddCollection<TEntityType>(Lambda idFieldExpression, Lambda fkFieldExpression, string nameSingular, string namePlural, string description, string iconSingular, string iconPlural, Lambda collectionConfig = null) : ContextAppConfigBuilder** |
136 | 220 |
|
137 | | -Adds a collection to the current context app with the given names, description and icons. An ID property accessor expression is required so that Umbraco UI Builder knows which property is the ID property. A foreign key property accessor is also required so that Umbraco UI Builder knows which property holds the Umbraco nodes UDI value. You can read more about this in the [Collections documentation](../collections/overview.md). |
| 221 | +Adds a collection to the current context app with the specified names, descriptions, and custom icons. Each collection requires an ID field and a foreign key field, linking to Umbraco node UDI values. For more details, see the [Collections](../collections/overview.md) article. |
| 222 | + |
| 223 | +#### Method Syntax |
| 224 | + |
| 225 | +```cs |
| 226 | +AddCollection<TEntityType>( |
| 227 | + Lambda idFieldExpression, |
| 228 | + Lambda fkFieldExpression, |
| 229 | + string nameSingular, |
| 230 | + string namePlural, |
| 231 | + string description, |
| 232 | + string iconSingular, |
| 233 | + string iconPlural, |
| 234 | + Lambda collectionConfig = null |
| 235 | +) : ContextAppConfigBuilder |
| 236 | +``` |
| 237 | + |
| 238 | +#### Example |
138 | 239 |
|
139 | 240 | ```csharp |
140 | | -// Example |
141 | | -contextAppConfig.AddCollection<Comment>(p => p.Id, "Comment", "Comments", "A collection of comments", "icon-chat", "icon-chat", collectionConfig => { |
142 | | - ... |
143 | | -}); |
| 241 | +contextAppConfig.AddCollection<Comment>( |
| 242 | + p => p.Id, |
| 243 | + "Comment", |
| 244 | + "Comments", |
| 245 | + "A collection of comments", |
| 246 | + "icon-chat", |
| 247 | + "icon-chat", |
| 248 | + collectionConfig => { |
| 249 | + // Collection configuration here |
| 250 | + } |
| 251 | +); |
144 | 252 | ``` |
0 commit comments