Skip to content

Commit 9d6f977

Browse files
committed
Renamed signs to flags
1 parent 65c4eb2 commit 9d6f977

File tree

4 files changed

+89
-89
lines changed

4 files changed

+89
-89
lines changed

16/umbraco-cms/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
* [Using Azure Blob Storage for Media and ImageSharp Cache](extending/filesystemproviders/azure-blob-storage.md)
255255
* [Configuring Azure Key Vault](extending/key-vault.md)
256256
* [Server Events From SignalR](extending/server-events.md)
257-
* [Sign Providers](extending/sign-providers.md)
257+
* [Flag Providers](extending/flag-providers.md)
258258
* [Packages](extending/packages/README.md)
259259
* [Creating a Package](extending/packages/creating-a-package.md)
260260
* [Language file for packages](extending/packages/language-files-for-packages.md)

16/umbraco-cms/customizing/back-office-signs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For example, a document scheduled for future publishing will have the following
1616
],
1717
```
1818

19-
The server determines which signs are present in the response via the registered collection of [sign providers](../extending/sign-providers.md). A client-side extension point determines how each sign is displayed in the backoffice.
19+
The server determines which signs are present in the response via the registered collection of [flag providers](../extending/flag-providers.md). A client-side extension point determines how each sign is displayed in the backoffice.
2020

2121
## Displaying a Sign
2222

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
description: Describes how to use provide flags in management API responses for use in presenting additional details to consumers.
3+
---
4+
5+
# Flag Providers
6+
7+
The Umbraco management APIs for trees, collections and items include a `flags` collection for each item. These indicate additional information for the item that can presented to users.
8+
9+
The Umbraco backoffice will use this to provide additional overlay icons on tree, collection and item presentations. This core behavior and extension point is described in the article on [backoffice signs](../customizing/back-office-signs.md).
10+
11+
## Core Flag Providers
12+
13+
Umbraco ships with four flag providers that will provide indications of the following document or media states:
14+
15+
- **Is Protected** - indicates the document is not available for public access.
16+
- **Has Pending Changes** - indicates that the document is published but has changes in draft waiting for publication
17+
- **Has Schedule** - indicates that the document is scheduled for publishing in the future
18+
- **Has Collection** - indicates that the document or media is based on a content type that is configured for display as a collection
19+
20+
For example, an item that is scheduled for publication would contain the following in the tree, collection or item API response:
21+
22+
```json
23+
"flags": [
24+
{
25+
"alias": "Umb.ScheduledForPublish"
26+
}
27+
],
28+
```
29+
30+
## Providing a Custom Flag Provider
31+
32+
If your package or project needs to present additional information for a tree, collection or item value, a custom flag provider can be created. This will be coupled with a presentation extension to determine how the information is interpreted for display as a [backoffice sign](../customizing/back-office-signs.md).
33+
34+
To create a flag provider, implement the `IFlagProvider` interface. There are two methods to implement:
35+
36+
- `CanProvideFlags<TItem>` - returns `bool` indicating whether this provider can provide flags for the tree, collection or item view model.
37+
- `PopulateFlagsAsync<TItem>(IEnumerable<TItem> itemViewModels)` - populates the `Flags` property for the provided collection of view models.
38+
39+
An illustrative implementation is as follows:
40+
41+
```csharp
42+
using Umbraco.Cms.Api.Management.ViewModels;
43+
using Umbraco.Cms.Core;
44+
45+
internal class MyDocumentFlagProvider : IFlagProvider
46+
{
47+
private const string Alias = Constants.Conventions.Flags.Prefix + "MyDocumentFlag";
48+
49+
// Indicate that this flag provider only provides flags for documents.
50+
public bool CanProvideFlags<TItem>()
51+
where TItem : IHasFlags =>
52+
typeof(TItem) == typeof(DocumentTreeItemResponseModel) ||
53+
typeof(TItem) == typeof(DocumentCollectionResponseModel) ||
54+
typeof(TItem) == typeof(DocumentItemResponseModel);
55+
56+
public Task PopulateFlagsAsync<TItem>(IEnumerable<TItem> itemViewModels)
57+
where TItem : IHasFlats
58+
{
59+
foreach (TItem item in itemViewModels)
60+
{
61+
if (ShouldAddFlag(item))
62+
{
63+
item.AddFlag(Alias);
64+
}
65+
}
66+
67+
return Task.CompletedTask;
68+
}
69+
70+
private bool ShouldAddFlag(TItem item) => return true; // Provide custom logic here.
71+
}
72+
```
73+
74+
The flag provider needs to be registered with Umbraco in a composer or application startup with:
75+
76+
```csharp
77+
builder.FlagProviders()
78+
.Append<MyDocumentFlagProvider>();
79+
```
80+
81+
For some flags, there may be sufficient information on the view models to map whether a flag should be created.
82+
83+
For an example of this, please see the core flag provider `IsProtectedFlagProvider` whose [source code can be found here](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Cms.Api.Management/Services/Flags/IsProtectedFlagProvider.cs).
84+
85+
More complex flags will require additional information, using the identifiers of the view models to retrieve the necessary data. Note here that it's important to try to avoid "N+1" issues. The aim should be to retrieve all the data needed to populate the flags for the whole collection in one step.
86+
87+
In core, the flag provider `HasScheduleFlagProvider` shows a good example of this. The [source code can be found here](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Cms.Api.Management/Services/Flags/HasScheduleFlagProvider.cs).

16/umbraco-cms/extending/sign-providers.md

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)