Skip to content

Commit dbb9ac9

Browse files
committed
Update property actions doc
1 parent 542d4c3 commit dbb9ac9

File tree

2 files changed

+47
-84
lines changed

2 files changed

+47
-84
lines changed
46.4 KB
Loading

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

Lines changed: 47 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,104 +8,67 @@ 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 in **Umbraco** that allow you to add extra functionality to a Property Editor.
12+
Think of them as small, secondary actions you can attach to a property without modifying the editor ifself.
1213

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.
14+
Property Actions appear as a small button next to the property label, 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.
1415

15-
## Data Structure of Property Actions
16+
## Property Actions in the UI <a href="#property-actions-in-the-ui" id="property-actions-in-the-ui"></a>
1617

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

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.
23+
## Registering a Property Action <a href="#registering-a-property-action" id="registering-a-property-action"></a>
3624

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-
}
59-
60-
var propertyActions = [
61-
myAction
62-
];
25+
{% hint style="info" %}
26+
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).
27+
{% endhint %}
6328

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

74-
### Component Implementation
75-
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.
52+
Every Property Action needs a class that defines what happens when the action is executed.
53+
You can extend the `UmbPropertyActionBase` class for this.
7754

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-
});
8955
```
56+
import { UmbPropertyActionBase } from '@umbraco-cms/backoffice/property-action';
57+
import { UMB_PROPERTY_CONTEXT } from '@umbraco-cms/backoffice/property';
9058
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(...)`.
59+
export class MyPropertyAction extends UmbPropertyActionBase {
60+
async execute() {
61+
const propertyContext = await this.getContext(UMB_PROPERTY_CONTEXT);
9262
93-
```js
94-
var myAction = {
95-
labelKey: 'general_labelForMyAction',
96-
labelTokens: [],
97-
icon: 'action',
98-
method: myActionExecutionMethod,
99-
isDisabled: false
63+
// Example: set a default value
64+
propertyContext.setValue("Default text here");
65+
}
10066
}
67+
export { MyPropertyAction as api };
68+
```
10169

102-
var propertyActions = [
103-
myAction
104-
];
70+
#### How it works:
10571

106-
this.$onInit = function () {
107-
if (this.umbProperty) {
108-
this.umbProperty.setPropertyActions(propertyActions);
109-
}
110-
};
111-
```
72+
`execute()` is called when the editor clicks the action.
73+
`getContext(UMB_PROPERTY_CONTEXT)` gives you access to the current property’s state.
74+
From there, you can modify the property (e.g., reset, update, or perform another operation).

0 commit comments

Comments
 (0)