Wednesday, February 9, 2011

Changing Master Language in EPiServer CMS 6

Yesterday I faced a problem that I had met before; I needed to change the master language of an EPiServer CMS site. I have done successfully using the awesome tool called Advanced Language Manipulation Tool for EPiServer by Adam Najmanowicz, but that time I used it on a EPiServer CMS 5 site.

When doing a little bit of searching I found that Mari Jørgensen had made some updates to the tool and uploaded it to Coderesort. So I grabbed it from there instead of from its original source.

It turns out it works like a charm in EPiServer CMS 6 as well, although the look and feel was a bit off:

Admin-Mode-Advanced-Language-Tool

However one thing that I forgot after I had updated the master language from English (en) to Australian English (en-au) was to enable the new language. The result was that I could not create any new pages, the option for creating new pages was disabled.

Edit-Mode-Tool-bar

It took me a little while before I thought of enabling the language, but once that was done everything worked great! Just go to Language Settings for the Start page in Edit Mode and enable the language of your choice.

Edit-Mode-Language-Settings

Monday, December 13, 2010

Updated WAVE Checker Plug-In

All of you accessibility fans out there are probably aware of a web site called WAVE. Wave is a free web based accessibility tool provided by WebAIM. If you know about this tool and EPiServer, you have probably come across Allan’s nice WAVE plug-in for EPiServer CMS.

A couple a weeks ago I came across a scenario where I wanted to use Allan’s plug-in a demo scenario. “Too easy” I thought to myself, just drop the DLL in the bin folder an let’s rock. However on this demo site I was using PageTypeBuilder, and it turns out that the way Allan’s plug-in added the context menu item was a bit too late in the page life cycle. Therefore I took the freedom to copy Allan’s code and modify it a bit to work with PageTypeBuilder – I hope Allan doesn’t mind ;)

WAVE-Checker-PlugIn

In the process I also added language support and created a small icon that is shown in the context menu. Feel free to download the source code here.

Disclaimer: Please note that the code comes as-is and I will not be held responsible.

Thursday, November 18, 2010

Search CMS Pages in Relate+ 2.0

The new search function in Relate+ 2.0 is really powerful. Relate+ will populate the search index with community content, CMS pages and files out-of-the-box. However the search page that is included in the templates will only search community content.

Eric Pettersson has blogged about adding CMS page search to the search page of Relate+ 2.0 – this is great! However he left out a few steps that you have to take to make the search work completely. In this blog post I will highlight these steps. I will assume that you have read Eric’s post and implemented that part already.

If you have followed Eric’s steps and then played around with your site, the chances are good that your index is a bit off – especially if you have deleted pages. Because of this, the first thing that we want to do is re-build the index. This is done using this code snippet:

EPiServer.Search.SearchHandler.Instance.ResetIndex("default");
EPiServer.Community.Search.SearchHandler.Instance.AddCommunityEntitiesToIndex(true);            
EPiServer.Templates.RelatePlus.CmsModules.CmsSearchHandler.Instance.IndexPublishedCmsPages();

The “default” is the name of your index, change it if you have changed the name of the index. You can find that code in the attached ReIndexRelatePlus2.aspx – this is a modified version of the re-index page found here. Simply place the file in your web root and run it.
Now locate the file CmsIntegrationModule.cs in /Templates/RelatePlus/InitializationModules/and have a look at the method called Instance_MovedPage. We need to modify this version so that the search index is always updated. In the code that you get out-of-the-box the search index will only be updated if the Club association has been effected. Change the code to something like this:

private static void Instance_MovedPage(object sender, PageEventArgs e)
{
    // Guard
    if (e == null || PageReference.IsNullOrEmpty(e.PageLink)) return;

    // Remove the page from cache due to Bug #24524 where IsDeleted gets its value from cache.
    DataFactoryCache.RemovePage(e.PageLink);
    PageData currentPage = EPiServer.DataFactory.Instance.GetPage(e.PageLink);

    // Update this page in search index
    // Since we don't want pages from the recycle bin in search result, we remove them from index
    if (currentPage.IsDeleted)
    {
        CmsSearchHandler.Instance.UpdateIndex(currentPage, IndexAction.Remove);
    }
    else
    {
        CmsSearchHandler.Instance.UpdateIndex(currentPage, IndexAction.Update);
    }

    // Get the club id
    int clubId = GetClubId(e.PageLink);

    if (clubId != -1)
    {
        // Get the club
        Club associatedClub = ClubHandler.Instance.GetClub(clubId);
        if (associatedClub != null)
        {
            Club clubClone = associatedClub.Clone() as Club;

            if (currentPage.IsDeleted)
            {
                clubClone.RemoveAssociatedPage(currentPage);
                ClubHandler.Instance.UpdateClub(clubClone);
            }
        }
    }
}

In this code I have also changed it so that when a page is deleted, i.e. moved to the recycle bin, the page is removed from the search index. This is done since we do not want to include deleted pages in the search result.

You can find the entire source code here. Enjoy!

Disclaimer: Please note that the code comes as-is and I will not be held responsible.