Trying to add a workspace action to the
# package-development
s
Trying to add a workspace action to the user edit workspace, but how can I get the context? I can see the source imports it from a local file, not from the backoffice package. Is that part just not ready yet?
import { UMB_USER_WORKSPACE_CONTEXT } from './user-workspace.context-token.js';
w
Consume Context is your friend
Ah gotcha problem - yeh where its not referenced like
import { UMB_WORKSPACE_CONTEXT, UmbWorkspaceContextInterface } from "@umbraco-cms/backoffice/workspace";
ie from a package as such, where the one you want seems to be internal and not published as part of a package from what I understand. So you can't reference the context
UMB_USER_WORKSPACE_CONTEXT
May be a context that got overlooked to be made available I am guessing ?! I am sure the friendly crew @Jacob Overgaard or @Niels Lyngsø can advise.
n
Yes, the last point Warren made here is the problem. Its missing an export. Cause the idea is that there should be general, interface specfic and specific tokens for each workspace. So what @skttl wanted to, should be posible, in this manner:
import { UMB_USER_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/user'
when the tokens gets exported correctly.
m
Did you look at the
UmbElementMixin
? They are using the
UmbContextConsumerController
to provide the "consume context" method
I guess this should work from anywhere that you have something that "hosts" the controller, new UmbContextConsumerController(hostingElement,token,callback)
Copy code
consumeContext<BaseType = unknown, ResultType extends BaseType = BaseType>(
            alias: string | UmbContextToken<BaseType, ResultType>,
            callback: UmbContextCallback<ResultType>,
        ): UmbContextConsumerController<BaseType, ResultType> {
            return new UmbContextConsumerController(this, alias, callback);
        }
15 Views