Try our conversational search powered by Generative AI!

David Sandeberg
May 18, 2010
  8728
(2 votes)

Hiding pages in EditTree

A problem for some of our customers with globalized websites is that the EditTree gets cluttered with pages only existing in one or a few languages.

The pages get displayed in italics and this, I take it, is a feature making it easy to get an overview of pages not having a language version in the selected language and also making it easy to create that version. This is fine when working with languages as intended by EPiServer, that is where all pages exists in all languages in a 1:1 relationship. This is however not the reality for several of our customers since they need to have different content in different market areas leading to a different page structure with different page types.

One of the new features of CMS 6 is the ability to assign access rights on languages. While this is a great improvement like many other things in the new release I was hoping for an option to hide pages that does not exist in a language accessible by the editor. This would solve the problem for editors only editing one language. When i couldn’t find this opiton I asked the EPiServer support team if this could be achieved in any way. They pointed me to a useful forum post that helped to get me started.

The goal of this post is a walk through of making a httpModule that hides pages in the EditTree based on

- Access rights on language

- Access rights in page structure

- The selected language in the drop down under the EditTree

 

First, we need to define a class that inherits from IHttpModule and hook into the DataFactorys FinishedLoadingChildren event.


public class PageExcluder: IHttpModule {

public void Dispose() {}

public void Init(HttpApplication context) {
EPiServer.DataFactory.Instance.FinishedLoadingChildren += new EPiServer.ChildrenEventHandler(Instance_FinishedLoadingChildren);
}

void Instance_FinishedLoadingChildren(object sender, EPiServer.ChildrenEventArgs e) {

}
}

 

This method gets called each time children is loaded so we need to make sure we only hide pages when actually loading the EditTree

if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith("EditTree.aspx")) {

 

Now we need to iterate over the pages that has been loaded from the data factory

for (int i = 0; i < e.Children.Count; i++) {

 

While doing this we want to remove any pages that:

- Is not editable by the user based on access rights set on the language

// get the languages the user has access to edit
StringCollection languageAccess = new StringCollection();
foreach (LanguageBranch language in LanguageBranch.ListAll()) {
if (language.ACL.QueryDistinctAccess(EPiServer.Security.AccessLevel.Edit)) {
languageAccess.Add(language.LanguageID);
}
}
// remove pages that the user has no access to edit
if (!languageAccess.Contains(e.Children[i].LanguageID)) {
e.Children.RemoveAt(i);
i--;
continue;
}

 

- Is not editable by the user based on access rights set in the page structure

if (!e.Children[i].QueryDistinctAccess(EPiServer.Security.AccessLevel.Edit)) {
e.Children.RemoveAt(i);
i--;
continue;
}

 

- Does not have a language version in the language selected by the user in the drop down under the edit tree.

string selectedEditLang;
if (HttpContext.Current.Request.Cookies["editlanguagebranch"] != null)
selectedEditLang = HttpContext.Current.Request.Cookies["editlanguagebranch"].Value;
else
selectedEditLang = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

if (e.Children[i].LanguageID != selectedEditLang) {
e.Children.RemoveAt(i);
i--;
continue;
}

 

In the complete version of this module you can specify which one(s) of these checks you want to do by adding entries to your appSettings. You can download the complete project here.

 

This is my first blog post here on EPiServer world and i hope you found it useful. I appreciate any feedback, improvements or suggestions.

May 18, 2010

Comments

Sep 21, 2010 10:33 AM

Thank you for the nice information David. This can sure be useful!

Good blog start, keep it up =)

Adam Jenkin
Adam Jenkin May 3, 2012 03:02 PM

Hi David,

Many thanks, have just implemented this into a site I am working on (CMS6 R2) - I made a few changes - mainly by using an Initialisation Module and enabling the settings to be controlled through plugin settings (by site admin's) rather than appSettings.

Happy to send the code over to you if you want to update the download.

Adam

Lise Engmo Eggum
Lise Engmo Eggum May 7, 2012 03:58 PM

This is great! Adam; would love to see it with your extensions also.

Lise Engmo Eggum
Lise Engmo Eggum May 15, 2012 01:39 PM

Hi David! I have an issue when activating the "hide/show pages pased on the selected language in the drop down under the EditTree"; the waste basket is hidden for everyone. Any idea how to make that one visible?

Neil F
Neil F May 25, 2012 02:18 PM

LiseEE - I had the same problem, also noticed that the tree did not expand at all until selecting on/off a language, I suspect unless US at the top - allowing root page regardless of language check fixed both bugs. I'm only using the selected language check, so similar may be necessary on the other options:

if (e.Children[i].LanguageID != selectedEditLang && e.PageLink.ID != PageReference.RootPage.ID)
{
e.Children.RemoveAt(i);
i--;
continue;
}

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024