You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 16/umbraco-cms/customizing/property-editors/property-actions.md
+47-84Lines changed: 47 additions & 84 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,104 +8,67 @@ description: Guide on how to implement Property Actions for Property Editors in
8
8
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.
9
9
{% endhint %}
10
10
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.
12
13
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.
14
15
15
-
## Data Structure of Property Actions
16
+
## Property Actions in the UI <ahref="#property-actions-in-the-ui"id="property-actions-in-the-ui"></a>
16
17
17
-
Property Actions are an array of objects defining each action. An action is defined by the following properties:
<figcaption><p><strong>Property action in Block List</strong></p></figcaption>
21
+
</figure>
18
22
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 <ahref="#registering-a-property-action"id="registering-a-property-action"></a>
36
24
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
-
functionmyActionExecutionMethod() {
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).
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
67
45
}
68
-
};
46
+
};
69
47
70
-
71
-
});
48
+
extensionRegistry.register(manifest);
72
49
```
50
+
### Creating the Property Action Class <ahref="#creating-the-property-action-class"id="creating-the-property-action-class"></a>
73
51
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.
import { UmbPropertyActionBase } from '@umbraco-cms/backoffice/property-action';
57
+
import { UMB_PROPERTY_CONTEXT } from '@umbraco-cms/backoffice/property';
90
58
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 {
0 commit comments