How to set default culture variant in Umbraco v15/v16 (ContentSendingNotification removed)

,

Hi all

In Umbraco v13, I was able to use ContentSendingNotification to set the default culture for document variants with code like this:


var variants = notification.Content.Variants
    .Where(v => cultureCodes.Any(code => code == v.Language?.IsoCode))
    .ToArray();

if (defaultIsoCode !=null) {
     var defaultVariant = variants.FirstOrDefault(v => v.Language?.IsoCode == defaultCultureCode);
     if (defaultVariant?.Language != null)
    {
         defaultVariant.Language.IsDefault = true;
   } 
}
notification.Content.Variants = variants;

With this, I could set the document’s variants and mark the default culture.

However, in Umbraco v15/v16 the ContentSendingNotification has been removed.
:backhand_index_pointing_right: What’s the correct way to achieve the same functionality in these newer versions?

Thanks in advance! :folded_hands:

The important question here for better understanding the issue: WHY do you need this? What problem do you fix with this? Understanding this makes it easier to come up with a solution. There is as far as I know not a replacement.

Because in our setup we have multiple websites, each with their own language setup.
For example:

  • The French sites only have en-GB and fr-FR
  • Our Belgium site has nl-BE and fr-BE

We’ve added properties where an editor can define which cultures are available for a given site, and also pick the default language.

When creating a document, we previously used ContentSendingNotification to tell Umbraco:

  • what the default language of the site is
  • which cultures the editor should be able to select

This made it much easier for editors to work with content, because the CMS only showed the relevant cultures for that site and automatically marked the correct default.

Without this, it’s harder to guide editors and keep culture selection consistent across sites.