How to create an entity action with dialogue in U1...
# package-development
d
Hey all, I'm trying out the U14 rc1 today and attempting to get a simple
Entity Action
working that opens a panel, much like the old menu items with the
LaunchDialogView
options. In particular for content items in the content tree. I'm struggling to get this to work, does anybody happen to have something already that I can steal take inspiration from? Right now I'm getting an error saying:
Copy code
Extension of alias "contentgenerator.entity.action" did not succeed creating an Element with Api, Api was created but the Element was missing a JavaScript file via the 'element' or the 'js' property. Alternatively define a Element Name in 'elementName' in the manifest.
I'll give some more context in a thread
I'm defining a modal and an entity action in typescript like this:
Copy code
ts
import { UMB_DOCUMENT_ENTITY_TYPE } from "@umbraco-cms/backoffice/document";
import { ManifestEntityAction, ManifestModal } from "@umbraco-cms/backoffice/extension-registry";
import { ContentGeneratorEntityAction } from "./content.api";
import { CONTENTGENERATOR_MODAL_ALIAS } from "./content.modal";
import { ContentGeneratorContent } from "./content.lit";

const entityAction: ManifestEntityAction = {

    type: 'entityAction',
    alias: 'contentgenerator.entity.action',
    name: 'Content generator context menu',
    weight: 2000,
    api: ContentGeneratorEntityAction,
    forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
    meta: {
        icon: 'fire',
        label: 'Generate random content'
    }
}

const modal: ManifestModal = {
    type: 'modal',
    alias: CONTENTGENERATOR_MODAL_ALIAS,
    name: 'Content generator modal',
    element: ContentGeneratorContent
}

export const manifests = [entityAction, modal];
And then in my index.ts, I have this registration code:
Copy code
ts
import { UmbEntryPointOnInit } from '@umbraco-cms/backoffice/extension-api'
import { manifests as contentmenumanifests } from './contentmenu/manifest'

export const onInit: UmbEntryPointOnInit = (_host, extensionRegistry) => {

    extensionRegistry.registerMany([
        ...contentmenumanifests
    ])
}
It seems to recognize this, because it seems to attempt to create the entity action, but is failing somewhere
I can't really get anything similar to the docs to build when it comes to the ContentGeneratorEntityAction class: https://docs.umbraco.com/umbraco-cms/v/14.latest-rc/extending-backoffice/extension-types/entity-actions#the-entity-action-class It doesn't recognize
UMB_MODAL_SERVICE_CONTEXT
, the constructor doesn't have the same arguments and the
@umbraco-cms/modal
import isn't recognized https://cdn.discordapp.com/attachments/1232719996543827968/1232721403938082816/image.png?ex=662a7cc5&is=66292b45&hm=66fb8525fe189dec4ca012f2bac94c4d4ef81f86ae60f3324b4c765811857dcb&
k
So my working ones are currently like this. Manifest :
Copy code
ts
{
    type: 'entityAction',
    kind: 'default',
    alias: 'usync.publish.push.action',
    name: 'Push action',
    api: () => import('./push.action.ts'),
    forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
    weight: 20,
    meta: {
        icon: 'icon-arrow-right',
        label: '#usyncpublish_pushItems',
    },
},
Entity action :
Copy code
ts
export class uSyncPushEntityAction extends UmbEntityActionBase<never> {
    #modalContext: UmbModalManagerContext | undefined;

    constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
        super(host, args);

        this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (_modalContext) => {
            this.#modalContext = _modalContext;
        });
    }

    async execute(): Promise<void> {
        const actionModalContext = this.#modalContext?.open(
            this,
            USYNC_PUBLISHER_ACTION_MODAL,
            {
                data: {
                    action: 'push',
                    unqiue: this.args.unique,
                    entityType: this.args.entityType,
                    mode: PublishMode.PUSH,
                },
            },
        );

        await actionModalContext?.onSubmit().catch((_rejected) => {
            return; // user pressed cancel.
        });

        return;
    }
}
I suspect its your
ContentGeneratorEntityAction
? does it have the execute method, and inherit from
umUmbEntityActionBase
?
looking at your screenshot , i think the context names might be wrong ? (e.g mine is UMB_MODAL_MANAGER_CONTEXT
*there is also thing (well there was in one of the late beta's) if you don't await the onsubmit then when you open from the tree menu it closes again. *
w
Feel free to look at Examine Peek as it an entity action basically opens a modal which sounds like the original thing your wanting to do But I think Kevin has got you covered
d
Awesome, thanks, I'm gonna read through all of these! πŸ’ͺ
And it opens the modal!! 😱
I added the interfaces to my manifest definitions so I get strongly typed support from my editor like this:
Copy code
ts
const entityAction: ManifestEntityAction = {

    type: 'entityAction',
    kind: 'default',
    alias: 'contentgenerator.entity.action',
    name: 'Content generator context menu',
    api: () => import('./content.api'),
    forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
    weight: 2000,
    meta: {
        icon: 'fire',
        label: 'Generate random content'
    }
}

const modal: ManifestModal = {
    type: 'modal',
    alias: CONTENTGENERATOR_MODAL_ALIAS,
    name: 'Content generator modal',
    element: () => import('./content.lit')
}
This seems to work
Also looks like the tree menu automatically takes the top-most entity action as secondary button inside the tree πŸ€” https://cdn.discordapp.com/attachments/1232719996543827968/1232924863287787531/image.png?ex=662b3a42&is=6629e8c2&hm=8ae120e23c7c6d2d5c3c7766f5749e64aedc6dab1c6b09cc0c8e8ba00f7e58fa&
w
Well your weight is set to 2000 so it’s probably higher than most things.
Best way is to goto the extensions in the settings section and pick entity actions to see all the others registered and what their weight are
d
Ya, I thought 2000 would put it at the back, but it puts it at the front. Just made it -2000 and now it's all good. Just surprising that the content tree updates with the order of the entity actions
w
Yeh its the opposite of current backoffice. Higher is first, where previously lower was first
k
I think it shoud go the other way, just because we are going to end up with negative weighting to get to the end of the list (and maybe that should be the thing, the last core one should be 0 ?). give how weight reall y means order maybe it should have been called order this time ? I doesn't really matter that much, it just has seemed a little odd to me coming from the old way.
w
Same
25 Views