Skip to content

Commit 6a5bd27

Browse files
Sofie Toft Kristensengitbook-bot
authored andcommitted
GITBOOK-40: Property Value Preset
1 parent 9fe3978 commit 6a5bd27

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

15/umbraco-cms/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
* [Entity Actions](customizing/extending-overview/extension-types/entity-actions.md)
196196
* [Entity Bulk Actions](customizing/extending-overview/extension-types/entity-bulk-actions.md)
197197
* [Entity Create Option Action](customizing/extending-overview/extension-types/entity-create-option-action.md)
198+
* [Property Value Preset](customizing/extending-overview/extension-types/property-value-preset.md)
198199
* [Trees](customizing/extending-overview/extension-types/tree.md)
199200
* [Global Context](customizing/extending-overview/extension-types/global-context.md)
200201
* [Localization](customizing/extending-overview/extension-types/localization.md)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
description: Provide a preset value for a Property.
3+
---
4+
5+
# Property Value Preset
6+
7+
The Property Value Preset is an Extension Type that uses an API to provide a Preset Value. The preset value is used when a user scaffolds a new set of Content.
8+
9+
The following Manifest declares a preset for the `Umb.PropertyEditorUi.TextBox` Property Editor UI:
10+
11+
```typescript
12+
export const manifest = {
13+
type: 'propertyValuePreset';
14+
alias: 'my.propertyValuePreset.TextBox',
15+
name: 'My Property Value Preset for TextBox',
16+
api: () => import('./my-property-value-preset.js'),
17+
forPropertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox'
18+
}
19+
```
20+
21+
Such Property Preset Value API could look like this:
22+
23+
{% code title="my-property-value-preset.js" %}
24+
```typescript
25+
export class MyPropertyValuePresetApi implements UmbPropertyValuePreset<string, UmbPropertyEditorConfig> {
26+
async processValue(value: undefined | string, config: UmbPropertyEditorConfig) {
27+
return value ? value : 'Hello there';
28+
}
29+
30+
destroy(): void {}
31+
}
32+
33+
export { UmbTrueFalsePropertyValuePreset as api };
34+
```
35+
{% endcode %}
36+
37+
This API will set the value to "Hello there" for all properties using the `Umb.PropertyEditorUi.TextBox` Property Editor UI.
38+
39+
### Target a Property Editor Schema
40+
41+
You can also choose to target your Preset for a Property Editor Schema.\
42+
\
43+
Define `forPropertyEditorSchemaAlias` to show the Preset Value for all Properties based on that Schema.
44+
45+
If both `forPropertyEditorSchemaAlias` and `forPropertyEditorUiAlias` are defined, it will not limit the target. The matching is independently for each of them.
46+
47+
Notice that `forPropertyEditorSchemaAlias` only targets the Properties used on the Content Type based data. This could affect Documents, Media, Members, and Blocks, and not properties of a Data Type Configuration.
48+
49+
## Utilize the Data-Type configuration
50+
51+
The `processValue` method takes two arguments, the current value of the Preset and the Data-Type Configuration.
52+
53+
The following example is the built-in Property Value Preset for the Umbraco Toggle. The Toggle Data Type has a 'preset state' configuration that is used as the value of the Toggle.
54+
55+
{% code title="my-property-value-preset.js" %}
56+
```typescript
57+
export class UmbTrueFalsePropertyValuePreset
58+
implements UmbPropertyValuePreset<UmbTogglePropertyEditorUiValue, UmbPropertyEditorConfig>
59+
{
60+
async processValue(value: undefined | UmbTogglePropertyEditorUiValue, config: UmbPropertyEditorConfig) {
61+
const initialState = (config.find((x) => x.alias === 'presetState')?.value as boolean | undefined) ?? false;
62+
return value !== undefined ? value : initialState;
63+
}
64+
65+
destroy(): void {}
66+
}
67+
68+
export { UmbTrueFalsePropertyValuePreset as api };
69+
```
70+
{% endcode %}
71+
72+
## Utilize anything
73+
74+
The `processValue` method is async. You can request the server or use the Context-API to retrieve the necessary information to construct your value.
75+
76+
{% hint style="info" %}
77+
**Only relevant for Umbraco 16 (release date: June 12th, 2025)**
78+
79+
For retrieving contexts, upgrading to version 16, where the `getContext` method will have a timeout feature is recommended. In this case, such will be needed for the preset not to get stuck if the context is unavailable when the reset is constructed.
80+
{% endhint %}
81+
82+
## Extend Presets
83+
84+
Because the `processValue` method takes a value as its first argument, you can append the value constructed by other Presets. In this way, multiple Presets can shape the preset value for a property.
85+
86+
In the case of multiple Property Value Presets targeting the same Property. The `weight` of the Manifest determines the order they are executed.
87+
88+
This opens up for you to overwrite or alter the Preset Value for Properties that use a Built-in Property Value Preset.

0 commit comments

Comments
 (0)