How to get current document culture version with L...
# help-with-umbraco
g
I'm building a custom Workspace View and I can get the basic document data, but I would like to get the info which document culture is currenty selected while editing. Is there a better user guide or a list of those tokens and all new stuff in Umbraco 14+ ? It's hard to dig examples from the code on GitHub I tried
import { UMB_VARIANT_WORKSPACE_CONTEXT, UMB_ENTITY_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace';
but I fail to get the info about the current culture of the document I'm editing. https://cdn.discordapp.com/attachments/1324669793818775594/1324669794162573385/image.png?ex=6778fe62&is=6777ace2&hm=a51d28c8f71edd11489ebf98d57c71b84fda4a628073f1ee2852ff0911bf26a3&
I tried now with
UMB_APP_LANGUAGE_CONTEXT
but I only get the app language, not the currently selected document language:
Copy code
this.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (instance) => {
    this._appLanguage = instance;
    this.observe(this._appLanguage.appLanguageCulture, (appCulture) => {
        this._appCulture = appCulture;

    });
});
Copy code
import { UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/document';
...
this.consumeContext(UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT, (context) => {
    this.observe(context.currentVariant, (currentVariant) => {
        this._variant = currentVariant;
    });
});
j
Does this work for you @gregor.tusar? I get the following error on the import statement:
Module '"@umbraco-cms/backoffice/document"' has no exported member 'UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT'
g
Yes it is working for me.
n
I would like to add. Yes what @gregor.tusar does work but is specific to the Document version of the Property Dataset Context, as you in this case get the Document-Variant info, including name in this example. To be a bit more generic, you should use the
UMB_CONTENT_PROPERTY_DATASET_CONTEXT
which would work for Blocks/Media/Member/... all the Content based types. (this may first be part of 15.2) But the best would be to base your code on the
UMB_PROPERTY_DATASET_CONTEXT
this is the most generic version of a Property Dataset Context, and since such is a requirement for implementing Property Editors, you can trust that such will always be found. Even when using your Property Editor UI as a Data-Type Configuration. This has a
getVariantId()
method which you can use to get the Variant ID, which holds the current Culture ISO code.
It could be nice if you could add this to the Docs — Would love to see how you would go about it, where and how you would expect to find such material. Thanks in advance
j
Ok I fix the missing import of
UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT
by upgrading the dev dependency
@umbraco-cms/backoffice
from 15.0.0 to 15.1.0. Does this mean it's not support before 15.1.0? But even with the import fixed, this
debugger
is never hit and the
_variant
is never set. Is this because I'm extending
UmbWorkspaceActionBase
or is there something else wrong?
Copy code
export default class MyCustomWorkspaceAction extends UmbWorkspaceActionBase {

    constructor(host: UmbControllerHost, args: UmbWorkspaceActionArgs<never>) {
        super(host, args);
    
        this.consumeContext(UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT, (context) => {
            this.observe(context.currentVariant, (currentVariant) => {
                debugger;
                this._variant = currentVariant;
            });
        });
    }
}
9 Views