Hello all! I am trying to migrate an umbraco package to v15 and I am having issues trying to figure out how to create a Content Picker. In angularJS I was able to do it by using editorService.contentPicker, however I cannot figure out how to do it with Lit and cannot find any documentation for it. Any help?
Thank you
Ok, I found the answer after many attempts. I’ll leave the answer here in case it will be useful to someone else.
first of all, import the following:
import { UmbModalManagerContext, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
import { UMB_DOCUMENT_PICKER_MODAL } from '@umbraco-cms/backoffice/document';
then create a button that opens the modal:
<uui-button look="secondary" label="Select..." @click=${this.chooseNode}></uui-button>
Implement implement the following in your constructor:
modalManager?: UmbModalManagerContext;
constructor() {
super();
this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (context) => {
this.modalManager = context;
});
}
then your chooseNode function that is triggered when the button is clicked:
chooseNode = () => {
if (!this.modalManager) {
return;
}
const modalHandler = this.modalManager.open(
this,
UMB_DOCUMENT_PICKER_MODAL,
{
data: {,
//insert here your options
//eg:
foldersOnly: true
},
value: {
selection: [],
},
}
);
modalHandler.onSubmit().then(async (response) => {
//do something on submit...
console.log(response);
});
};```
2 Likes
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.