Skip to content

Commit 0c18a33

Browse files
authored
Merge pull request #7451 from umbraco/update-property-actions
Property actions: rewrite Property Actions documentation
2 parents 136fad3 + d848178 commit 0c18a33

File tree

2 files changed

+46
-88
lines changed

2 files changed

+46
-88
lines changed
46.4 KB
Loading

16/umbraco-cms/customizing/property-editors/property-actions.md

Lines changed: 46 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,104 +8,62 @@ description: Guide on how to implement Property Actions for Property Editors in
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-
Property Actions are a built-in feature that provide a generic place for secondary functionality for property editors.
11+
Property Actions are a built-in feature of Umbraco that allows you to add extra functionality to a Property Editor. Think of them as small, secondary actions that you can attach to a property without modifying the editor itself.
1212

13-
Property Actions appear as a small button next to the label of the property, which expands to show the available actions. They are defined and implemented in the Property Editor, making it open as to what a Property Action is.
13+
Property Actions appear as a small button next to the property label, which expands to show the available actions.
1414

15-
## Data Structure of Property Actions
15+
## Property Actions in the UI
1616

17-
Property Actions are an array of objects defining each action. An action is defined by the following properties:
17+
<figure style="max-width:60%; margin:auto; text-align:center;">
18+
<img src="../../.gitbook/assets/property-actions-blocklist.png" alt="" style="max-width:60%; height:auto; display:block; margin:auto">
19+
<figcaption><p><strong>Property action in Block List</strong></p></figcaption>
20+
</figure>
1821

19-
```js
20-
{
21-
labelKey: 'clipboard_labelForRemoveAllEntries',
22-
labelTokens: [],
23-
icon: 'trash',
24-
method: removeAllEntries,
25-
isDisabled: true
26-
}
27-
```
28-
29-
We use `labelKey` and `labelTokens` to retrieve a localized string that is displayed as the Actions label. [See localization for more info.](../../extending/language-files/)
30-
31-
`isDisabled` is used to disable an Action, which change the visual appearance and prevents interaction. Use this option when an action wouldn't provide any change. In the example above, the action `remove all entries` would not have any impact if there is no entries.
32-
33-
## Implementation
34-
35-
The implementation of Property Actions varies depending on whether your Property Editor is implemented with a Controller or as a Component.
36-
37-
### Controller Implementation
38-
39-
When your Property Editor is implemented with a Controller, use the following approach for the Property Action:
40-
41-
```js
42-
angular.module("umbraco").controller("My.MarkdownEditorController", function ($scope) {
43-
44-
function myActionExecutionMethod() {
45-
alert('My Custom Property Action Clicked');
46-
// Disable the action so it can not be re-run
47-
// You may have custom logic to enable or disable the action
48-
// Based on number of items selected etc...
49-
myAction.isDisabled = true;
50-
};
51-
52-
var myAction = {
53-
labelKey: 'general_labelForMyAction',
54-
labelTokens: [],
55-
icon: 'action',
56-
method: myActionExecutionMethod,
57-
isDisabled: false
58-
}
22+
## Registering a Property Action
5923

60-
var propertyActions = [
61-
myAction
62-
];
24+
{% hint style="info" %}
25+
Before creating a Property Action, make sure you are familiar with the [Extension Registry in Umbraco](https://docs.umbraco.com/umbraco-cms/customizing/extending-overview/extension-registry/extension-registry).
26+
{% endhint %}
6327

64-
this.$onInit = function () {
65-
if ($scope.umbProperty) {
66-
$scope.umbProperty.setPropertyActions(propertyActions);
28+
Here is how you can register a new Property Action:
29+
```
30+
import { extensionRegistry } from '@umbraco-cms/extension-registry';
31+
import { MyEntityAction } from './my-property-action.api';
32+
const manifest =
33+
{
34+
type: 'propertyAction',
35+
kind: 'default',
36+
alias: 'My.propertyAction',
37+
name: 'My Property Action ',
38+
forPropertyEditorUis: ["my-property-editor"], // Target specific property editors
39+
api: () => import('./my-property-action.api.js'),
40+
weight: 10, // Order if multiple actions exist
41+
meta: {
42+
icon: 'icon-add', // Icon to display in the UI
43+
label: 'My property action', // Label shown to editors
6744
}
68-
};
69-
45+
};
7046
71-
});
47+
extensionRegistry.register(manifest);
7248
```
49+
### Creating the Property Action Class
7350

74-
### Component Implementation
51+
Every Property Action needs a class that defines what happens when the action is executed.
52+
You can extend the `UmbPropertyActionBase` class for this.
7553

76-
Follow this guide if your Property Editor is implemented as a Component. The Component must be configured to retrieve an optional reference to `umbProperty`. The requirement must be optional because property-editors are implemented in scenarios where it's not presented.
77-
78-
See the following example:
79-
80-
```js
81-
angular.module('umbraco').component('myPropertyEditor', {
82-
controller: MyController,
83-
controllerAs: 'vm',
84-
require: {
85-
umbProperty: '?^umbProperty'
86-
}
87-
88-
});
8954
```
90-
91-
See the following example for implementation of Property Actions in a Component, notice the difference is that we are parsing actions to `this.umbProperty.setPropertyActions(...)`.
92-
93-
```js
94-
var myAction = {
95-
labelKey: 'general_labelForMyAction',
96-
labelTokens: [],
97-
icon: 'action',
98-
method: myActionExecutionMethod,
99-
isDisabled: false
55+
import { UmbPropertyActionBase } from '@umbraco-cms/backoffice/property-action';
56+
import { UMB_PROPERTY_CONTEXT } from '@umbraco-cms/backoffice/property';
57+
58+
export class MyPropertyAction extends UmbPropertyActionBase {
59+
// The execute method is called when the user triggers the action.
60+
async execute() {
61+
// Retrieve the property’s current state,
62+
const propertyContext = await this.getContext(UMB_PROPERTY_CONTEXT);
63+
64+
// Here it's possible to modify the property or perform other actions. In this case, setting a value.
65+
propertyContext.setValue("Default text here");
66+
}
10067
}
101-
102-
var propertyActions = [
103-
myAction
104-
];
105-
106-
this.$onInit = function () {
107-
if (this.umbProperty) {
108-
this.umbProperty.setPropertyActions(propertyActions);
109-
}
110-
};
111-
```
68+
export { MyPropertyAction as api };
69+
```

0 commit comments

Comments
 (0)