Get Current Culture in Custom Property Editor when loaded in a Block Slide Out Panel

I am building a custom property editor that needs to pass the current culture in an API call.

My code is as follows:

  this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (dataset) => {

      if (!dataset) return;

         const variantId = dataset.getVariantId?.();

         const culture = variantId?.culture ?? undefined;

         console.log("Dataset culture:", culture);

    }).passContextAliasMatches();

This code works if my property editor is on the content node however it doesnt work if I am in the slide out panel. I thought adding .passContextAliasMatches() would resolve this however no luck.

Anyone done anything similar?

Hi Marc,

I would use the Variant Context, can you try this:

		this.consumeContext(UMB_VARIANT_CONTEXT, (context) => {
			this.observe(context?.variantId, (variantId) => {
				...
			});
		});

This one is properly first available in 17.2, but we introduced a new VariantId that you may need in your case; this one is relevant in the case of mixing ariant and invariant Blocks.
Cause when writting a invariant block, the variant id would have a null culture. But you may want to know the culture that the data is stored for, then you can use this:

		this.consumeContext(UMB_VARIANT_CONTEXT, (context) => {
			this.observe(context?.displayVariantId, (variantId) => {
				...
			});
		});

Let me know how it goes, Good luck :slight_smile:

Thanks Niels, will keep you posted. Laptop died this morning so just sorting things out and will check this code later today.

Hi Neils,

Getting the following error with the second example:

Property ‘displayVariantId’ does not exist on type ‘UmbVariantContext’

First example runs however culture is null as you explained.

Hi @marc_love, so then you’re in the same case as the reason for introducing the displayVariantId.
Please await 17.2 then.

The alternative here and now ‘hack’ would be to consume UMB_CONTENT_PROPERTY_DATASET_CONTEXT with .passContextAliasMatches() so you’re not blocked by the first property dataset it meets.

This will give you the variantId of the picked variant in the variant-selector.

But notice this will work well in Global Blocks, and there might be other future features that will ruin this. So again from 17.2 please use the UMB_VARIANT_CONTEXT as this is decoupled from the Block to belong on a Content(Document/Media/Member)

No worries, Niels, I can work around it for now :+1: