[Solved] How to get the current content's unique I...
# package-development
b
I'm adding a property editor ui which needs to get a list of available items from an API controller, The API controller needs the content id (unique) that's being edited. My issue is that the property being edited is on a block, so it's displayed in the modal. I can't seem to find a context that will give me the unique of the content item being edited. I've tried using but there's nothing obvious. Any ideas, anyone had a similar issue?
n
I assume your experience is that if you consume
"UmbWorkspaceContext"
then you get the Blocks Workspace? But you would want to consume the Document Workspace... — Lets hope I assumed right. Then your option is to use a more specific Context Token, there is one specific for Document, called:
UMB_DOCUMENT_WORKSPACE_CONTEXT
The technical difference from just using a Context-Alias, to using a Context Token is that it comes with a discriminator, which makes the match more specific. This makes it only find a workspace context if its of the type Document. But thats not enough, cause pr. default you can only consume the nearst Workspace Context , like when working in inifinte editors you will only be able to get the nearest Context of that Context-Alias. Our context system is made to stop if there was a match on the Context Alias. But you can opt in to ignorer this and continue the search for a perfect match. — I can explain why we do this if you like. Here is an example of doing that:
Copy code
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => {
    console.log("got the context", context)
}).passContextAliasMatches();
b
Thanks Niels, I'll try this morning. I wasn't using the
"UmbWorkspaceContext"
alias, only tokens, but found the call back function in
consumeContext
wasn't getting run for
UMB_DOCUMENT_WORKSPACE_CONTEXT
. I'm hoping the application of
passContextAliasMatches()
will change that. I'm very new to JS/TS web frameworks, been such a steep learning curve 😓
Hi Niels, just reporting back. using
passContextAliasMatches()
did the trick. Thanks very much for your help here. Hopefully this frontend frame work will start to click for me soon.
n
Hi @Ben no worries, I think we owe you some guide/documentation that explains the system. Will come one day 🙂
69 Views