rickbutterfield
01/28/2025, 11:49 AMUMB_DOCUMENT_WORKSPACE_CONTEXT
when I'm inside of a block modal (UMB_BLOCK_WORKSPACE_CONTEXT
)leekelleher
01/29/2025, 10:54 AMmodalContext
property, which you can get access to the host element, from which you can get access to the Document Workspace Context.
e.g. something like this...
const host = blockContext.modalContext.getHostElement();
host.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (docContext) => {
console.log('UMB_DOCUMENT_WORKSPACE_CONTEXT', docContext);
});
Alternatively, if you are only after getting the document's ID, then you could try consuming the UmbMenuStructureWorkspaceContext
... this is the context for the breadcrumbs in the footer. Feels slight misuse, but that's how I'm using it in Contentment.
e.g. https://github.com/leekelleher/umbraco-contentment/blob/dev/v6.x/src/Umbraco.Community.Contentment.Client/src/property-editor-ui/data-picker/data-picker.element.ts#L75-L82rickbutterfield
01/30/2025, 11:40 AMNiels Lyngsø
02/10/2025, 1:37 PMpassContextAliasMatches
and you go about it in this way:
this.consumeContext(MY_SPECIFIC_TOKEN, (context) => {
...
}).passContextAliasMatches();
What happens when this is not turned on, is that the request stops at a Context Alias match.
This prevents you from accidentally retrieving a parent context of another scope than the one you are interested in.
But in this case you know what you are looking for, and you are clearly looking to retrieve something above the current Workspace.
If you dig deeper, you will see that all Workspace Contexts uses the same Context Alias, which is why you without this setting, are not able to escape it.
So the difference between UMB_WORKSPACE_CONTEXT and these
UMB_NAMEABLE_WORKSPACE_CONTEXT,
UMB_CONTENT_WORKSPACE_CONTEXT, UMB_BLOCK_WORKSPACE_CONTEXT, UMB_DOCUMENT_WORKSPACE_CONTEXT, + many more.
Is that these last four has further specifications to be meet before a match is accepted.
This can be used in two ways:
Your way, to only get a context that matches your exact needs.
And especially in combination with the passContextAliasMatches
you can pass through other sligtlhy similar contexts to get to it.
Another usage could be to use the retrival of a context, to determin the situation your code running from.
Example. consuming UMB_BLOCK_WORKSPACE_CONTEXT, without passContextAliasMatches
would only give a match if you are in a Block Workspace, then you could use that to act differently.
We use this our selfs to determine wether a Workspace should get a close button. By consuming the Modal Context we then know if we retrieved one we are inside a modal and will then display the close button.Niels Lyngsø
02/10/2025, 1:38 PMUMB_CONTENT_WORKSPACE_CONTEXT
in this way your code should be able to work when Blocks works on Media and Member. — Assuming what you want to do is supported by that interface. 👍