1

I am trying to only display certain languages for Editors in the Sitecore Content Editor Language dropdown/selector.

In the access viewer, it shows the permission correctly for the editors. (i.e. only have language read/write permission to the few languages in /system/languages for the editors). But, in content editor, it still display all the language options in the language selector.

When a language without permission selected, it displays "The security settings for the current language prevent you from seeing this item." warning.

But what I need is totally remove the languages without permission from the editor dropdown.

Any idea/help on this highly appreciated.

1 Answer 1

1

It looks like a bug in the Languages Gallery form (Sitecore.Shell.Applications.ContentManager.Galleries.Languages.GalleryLanguagesForm). The following code in the OnLoad method is expected to skip rendering languages if a user hasn't got Read access rights granted.

foreach (Language language in languages)
{
  Item languageItem = LanguageManager.GetLanguageItem(language, item.Database);
  // this is ALLWAYS null if a user hasn't got Read access
  if (languageItem != null)
  {
    if (!languageItem.Access.CanRead())
    {
      continue;
    }

...

Problem

The problem is in the if (languageItem != null) statement which is expected to be true to skip a language, but in fact it's always false because the user hasn't got the read access and cannot read the language item.

Workaround

You may try override the entire form code-behind class and skip languages if there are no corresponding language items found:

foreach (Language language in languages)
{
  Item languageItem = LanguageManager.GetLanguageItem(language, item.Database);
  // do not render language if it cannot be read
  if (languageItem == null)
  {
    continue;
  }

  if (!languageItem.Access.CanRead())
  {
    continue;
  }

The side effect of that is that all the languages from the core database that have not been duplicated in master will disappear. That's happening because in the code above the LanguageManager tries to read and check availability for languages from the item.Database only (which is master):

LanguageManager.GetLanguageItem(language, item.Database);
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.