Context Hunting - how do I get the culture of the ...
# package-development
w
Context hunting - help ! How do you find the context you want to use/consume ?
OK so I am after determining the culture that my custom UFM-Element WebComponent is in. I am trying various contexts and loosing the plot. I have used
<umb-debug visible dialog></umb-debug>
in order to try and help me out. But I am just as confused and with little luck :S
So how can I determine that I am in English or German from this scope in the DOM ?
Well ideally the cutlure code 'en' or 'de'
I can see some info in
UMB_CONTENT_WORKSPACE_CONTEXT.splitView.getActiveVariants()
Copy code
ts
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (ctx) => {
    console.log('UMB_CONTENT_WORKSPACE_CONTEXT.splitView.getActiveVariants()', ctx.splitView.getActiveVariants());
});
I was hoping a lower down context/scope say at the property level would be able to tell me what culture this is. Such as one of the BLOCK ones. Especially as blocks and its data can vary by culture now :S
Hoping that @Niels Lyngsø or @Jacob Overgaard might see this 🤞
OK seems like I found it after what seems like me trying all the contexts ! For anyone who reads this in the future and wants to know it was
UMB_BLOCK_MANAGER_CONTEXT
and observing the property
variantId
which is an object containing the culture and useful methods.
Copy code
ts
this.consumeContext(UMB_BLOCK_MANAGER_CONTEXT, (ctx) => {
    this.observe(ctx.variantId, (variantId) => {
        // console.log('UMB_BLOCK_MANAGER_CONTEXT.variantId.toCultureString', variantId?.toCultureString());
        // console.log('UMB_BLOCK_MANAGER_CONTEXT.variantId.Culture', variantId?.culture);

        this.culture = variantId?.culture;
    });
});
n
Yes, in the case of Blocks that is a fine choice. If you want to do similar in another Property Editor or want to be more generic, then the dataset is always present for all Property Editors and it knows its variant ID. that is thought specific to the variant begin open. if you want to be affected by the configuration of your property, (vary by culture). then the block Variant ID, get it from UMB_BLOCK_ENTRY_CONTEXT is affected by the configuration of the content element-type. meaning if that does not vary by culture, you will get a invariant variant id.
w
HUH - kinda confused... So I should try to use the dataset context or should I be using UMB_BLOCK_ENTRY_CONTEXT instead @Niels Lyngsø ?!
n
Depends on what you want. Again to do you want a variant ID that represents the Block? (Then pick entry) Or a variant ID of the current document-variant? (Then go with manager or dataset)
w
So an entire block can vary by language now can't it... So I better use the one closer to the block I suppose
n
Yep, again. You never told what you want to use it for. But it sounds right.
w
Sorry - you have to mind read 😛
Well its for a UFM for dictionary values to use in custom block views
For a client at the mo - but could be semi useful as a core UFM component IMO
But I need to know what places you currently use UFM to make it generic I suppose to work across all scenarios :S
n
Okay, so to be generic, then use the Property Dataset Context or if it should depend on the configuration of the Property, then the Property Context
9 Views