Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This page is a work in progress and may undergo further revisions, updates, or a
Entity Actions was previously called Tree Actions.
{% endhint %}

Entity Actions is a feature that provides a generic place for secondary or additional functionality for an entity type. An entity type can be a media, document and so on.
Entity Actions are a feature that provides a generic place for secondary or additional functionality for an entity type. An entity type can be a media, document and so on.

Items in an Umbraco Tree can have associated Actions. The actions visible to the currently logged in user can be controlled via User Permissions.

Expand Down Expand Up @@ -50,8 +50,12 @@ Sidebar Context Menu is an entity action that can be performed on a menu item. F

## Registering an Entity Action <a href="#registering-an-entity-action" id="registering-an-entity-action"></a>

{% hint style="info" %}
Before creating an Entity 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).
{% endhint %}

A minimal manifest looks like this:
```typescript
import { extensionRegistry } from '@umbraco-cms/extension-registry';
import { MyEntityAction } from './entity-action';

const manifest = {
Expand All @@ -67,8 +71,17 @@ const manifest = {
repositoryAlias: 'My.Repository',
},
};
```
And a simple implementation:
```typescript
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';

extensionRegistry.register(manifest);
export class MyEntityAction extends UmbEntityActionBase<any> {
async execute() {
//The execute() function is called when the user clicks on the custom Entity Action
}
}
export { MyEntityAction as api };
```

**Default Element**
Expand All @@ -79,11 +92,17 @@ interface UmbEntityActionElement {}

### The Entity Action Class <a href="#the-entity-action-class" id="the-entity-action-class"></a>

As part of the Extension Manifest you can attach a class that will be instanciated as part of the action. It will have access to the host element, a repository with the given alias and the unique (key etc) of the entity.
Each action is defined by a class that extends UmbEntityActionBase.
The class has access to:
- The **host element**
- A **repository** (using the provided alias)
- The entity’s **unique identifier**

The class either provides a getHref method, or an execute method. If the getHref method is provided, the action will use the link. Otherwise the `execute` method will be used. When the action is clicked the `execute` method on the api class will be run. When the action is completed, an event on the host element will be dispatched to notify any surrounding elements.
You can provide either:
- `getHref()` -> used if the action should **navigate**
- `execute()` -> used if the action should **run code**

Example of providing a `getHref` method:
Example: Using `getHref()`:

```typescript
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
Expand All @@ -101,7 +120,7 @@ export class MyEntityAction extends UmbEntityActionBase<MyRepository> {
}
```

Example of providing a `execute` method:
Example: Using `execute()`:

```typescript
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
Expand Down