Skip to content

Commit 9822667

Browse files
committed
Rewriting code samples for custom property editor support in headless for a modern approach that replaces IPublishedSnapshotAccessor
1 parent f629495 commit 9822667

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

16/umbraco-cms/reference/content-delivery-api/custom-property-editors-support.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
---
22
description: >-
3-
Discover how to customize the Content Delivery API's response for your custom
4-
property editors.
3+
Discover how to customize the Content Delivery API's response for custom property editors.
54
---
65

76
# Custom property editors support
87

9-
Out of the box, the Delivery API supports custom property editors, ensuring they are rendered alongside the built-in ones in Umbraco. However, if the output generated by your property editor isn't optimal for a headless context, you have the ability to customize the API response. This customization won't impact the Razor rendering, allowing you to tailor the Content Delivery API response according to your specific requirements.
8+
Out of the box, the Delivery API supports custom property editors, ensuring they are rendered alongside the built-in ones in Umbraco. However, if the output generated by a property editor isn't optimal for a headless context, developers can customize the API response. This customization won't impact the Razor rendering, allowing developers to tailor the Content Delivery API response according to their specific requirements.
109

11-
In this article, we'll look into how you can work with the `IDeliveryApiPropertyValueConverter` interface and implement custom [property expansion](./property-expansion-and-limiting.md) for your custom property editors.
10+
This article will demonstrate how to work with the `IDeliveryApiPropertyValueConverter` interface and implement custom [property expansion](./property-expansion-and-limiting.md) for custom property editors.
1211

1312
## Prerequisite
1413

1514
The examples in this article revolve around the fictional `My.Custom.Picker` property editor. This property editor stores the key of a single content item and is backed by a property value converter.
1615

17-
We will not dive into the details of creating a custom property editor for Umbraco in this article. If you need guidance on that, please refer to the [Creating a Property Editor](../../tutorials/creating-a-property-editor/README.md) and [Property Value Converters](../../customizing/property-editors/property-value-converters.md) articles.
16+
This article will not dive into the details of creating a custom property editor for Umbraco. Guidance on that can be found in these articles: [Creating a Property Editor](../../tutorials/creating-a-property-editor/README.md) and [Property Value Converters](../../customizing/property-editors/property-value-converters.md).
1817

1918
## Implementation
2019

21-
To customize the output of a property value editor in the Delivery API, we need to opt-in by implementing the `IDeliveryApiPropertyValueConverter` interface.
20+
To customize the output of a property value editor in the Delivery API, opt-in by implementing the `IDeliveryApiPropertyValueConverter` interface.
2221

23-
The code example below showcases the implementation of this interface in the property value converter for `My.Custom.Picker`. Our focus will be on the methods provided by the `IDeliveryApiPropertyValueConverter`, as they are responsible for customizing the Delivery API response.
22+
The code example below showcases the implementation of this interface in the property value converter for `My.Custom.Picker`. The focus will be on customizing the methods provided by the `IDeliveryApiPropertyValueConverter`, as they are responsible for customizing the Delivery API response.
2423

25-
Towards the end of the example, you will find the response models that we will be using.
24+
Response model classes can be found near the end of this article.
2625

2726
The `IsConverter()` and `GetPropertyValueType()` methods are inherited from the `PropertyValueConverterBase` class, which is covered in the [Property Value Converters](../../customizing/property-editors/property-value-converters.md) article.
2827

2928
{% include "../../.gitbook/includes/obsolete-warning-snapshot.md" %}
3029

3130
{% code title="MyCustomPickerValueConverter.cs" lineNumbers="true" %}
32-
3331
```csharp
3432
using Umbraco.Cms.Core.DeliveryApi;
3533
using Umbraco.Cms.Core.Models.DeliveryApi;
@@ -115,7 +113,6 @@ public class DeliveryApiItemDetails
115113
public IApiContentRoute? Route { get; set; }
116114
}
117115
```
118-
119116
{% endcode %}
120117

121118
The Implementation of the `IDeliveryApiPropertyValueConverter` interface can be found in the following methods:
@@ -163,9 +160,9 @@ GET /umbraco/delivery/api/v2/content/item/blog
163160

164161
## Property expansion support
165162

166-
Property expansion allows us to conditionally add another level of detail to the Delivery API output. Usually, these additional details are "expensive" to retrieve (for example, requiring database access to populate). By applying property expansion, we provide the option for the caller of the API to opt-in explicitly to this "expensive" operation. From the caller's perspective, the alternative might be an even more expensive additional round-trip to the server.
163+
Property expansion allows developers to conditionally add another level of detail to the Delivery API output. Usually, these additional details are "expensive" to retrieve (for example, requiring database access to populate). By applying property expansion, Umbraco developers provide the option for the caller of the API to opt-in explicitly to this "expensive" operation. From the caller's perspective, the alternative might be an even more expensive additional round-trip to the server.
167164

168-
In our example, property expansion is implemented within `ConvertIntermediateToDeliveryApiObject()`. By considering the value of the `expanding` parameter, we can modify the `BuildDeliveryApiCustomPicker()` method as follows:
165+
In this example, property expansion is implemented within `ConvertIntermediateToDeliveryApiObject()`. By considering the value of the `expanding` parameter, the `BuildDeliveryApiCustomPicker()` method can be modified as follows:
169166

170167
{% include "../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
171168

@@ -202,9 +199,9 @@ private DeliveryApiCustomPicker? BuildDeliveryApiCustomPicker(object inter, bool
202199
}
203200
```
204201

205-
If the `expanding` parameter is `false`, the method returns the same shallow representation of the referenced content item as before. Otherwise, we retrieve the corresponding `IPublishedContent` and construct our response object accordingly.
202+
If the `expanding` parameter is `false`, the method returns the same shallow representation of the referenced content item as before. Otherwise, retrieve the corresponding `IPublishedContent` and construct the response object accordingly.
206203

207-
To see the expanded output in the API response, we need to add the `expand` query parameter to our request. We can use either `?expand=properties[$all]` to expand all properties or `?expand=properties[pickedItem]` to expand the specific `'pickedItem'` property.
204+
To see the expanded output in the API response, add the `expand` query parameter to the request. This parameter can be applied using either `?expand=properties[$all]` to expand all properties or `?expand=properties[pickedItem]` to expand the specific `'pickedItem'` property.
208205

209206
**Request**
210207

0 commit comments

Comments
 (0)