London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

David Sandeberg
May 18, 2010
  9150
(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 Product Recommendation Troubleshooting

In today’s fast-paced digital landscape, personalization is everything . Customers expect relevant, tailored experiences whenever they interact wit...

Sanjay Kumar | Apr 28, 2025

Natural Language Q&A in Optimizely CMS Using Azure OpenAI and AI Search

In Part 2, we integrated Azure AI Search with Azure Personalizer to build a smarter, user-focused experience in Optimizely CMS. We used ServiceAPI ...

Naveed Ul-Haq | Apr 25, 2025 |

Identifying Spike Requests and Issues in Application Insights

Sometimes within the DXP we see specific Azure App Instances having request spikes causing performance degredation and we need to investigate. I fi...

Scott Reed | Apr 25, 2025

Optimizely Frontend Hosting Beta – Early Thoughts and Key Questions

Optimizely has opened the waitlist for its new Frontend Hosting capability. I’m part of the beta programme, but my invite isn’t due until May, whil...

Minesh Shah (Netcel) | Apr 23, 2025