Entity Actions Questions ❓
# package-development
w
**Question Time**: How does an Entity Action know to invoke the
Execute
method ?
So following along with @Kevin Jump & some core codebase diving. With an entity action its registered with a property called
api
in the
manifest
We have a method in the example code called
Execute()
I am unsure how the Entity Action in the dropdown knows how to run the
Execute
method when the item is clicked? So a wider a question how would I know to have called the method this (as I get no completions to know about this method) ? Can @Jacob Overgaard or @Niels Lyngsø perhaps shed some light on this for me please
Copy code
ts
import { UmbControllerHostElement } from "@umbraco-cms/backoffice/controller-api";
import { UMB_DOCUMENT_ENTITY_TYPE, UmbDocumentItemRepository } from "@umbraco-cms/backoffice/document";
import { UmbEntityActionBase } from "@umbraco-cms/backoffice/entity-action";
import { UMB_NOTIFICATION_CONTEXT, UmbNotificationContext } from "@umbraco-cms/backoffice/notification";

export class MyEntityAction extends UmbEntityActionBase<UmbDocumentItemRepository> {
    #notificationContext? : UmbNotificationContext;

    constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) {
        super(host, repositoryAlias, unique, UMB_DOCUMENT_ENTITY_TYPE)

        console.log('repository alias', repositoryAlias);
        console.log('unique', unique);
        console.log('entity type', this.entityType);
        
        this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
            this.#notificationContext = instance;
        });
    }
    
    // Question: How do we know what is calling the execute method
    async execute() {
        this.#notificationContext?.peek('warning', {
            data: {
                headline: 'A thing has happened !',
                message: 'What that thing is? only time will tell.'
            }
        });
    }
    
}
j
You are right, it's missing in the base class
if we did it proper, we should have an interface that lets you know to implement that and implement a crude version in the base class that throws an error basically
w
Thanks !!
j
....and @leekelleher saw fit to fix it already 😄 https://github.com/umbraco/Umbraco.CMS.Backoffice/pull/1291
w
@leekelleher you 🦵end
Remembered and re-found the other storybook site 🙂 This also mentions that there is
getHref
method as well or is the Storybook item describing actions out of date @Jacob Overgaard ? https://apidocs.umbraco.com/v14/ui/?path=/docs/guides-extending-the-backoffice-entity-actions--docs#the-entity-action-class
j
No you are right, you can still define that, and if you do, it won't call the execute method. Maybe we need to fix that as well, @leekelleher 🙂
w
Yes please - be good to make more people aware of that as well (if they just wanna use it as a deep link to something)
13 Views