Open items from bucket search in main content tree in Sitecore

Sitecore now provides us with this very useful ways of searching for items which are organized within item buckets.
We ran into a requirement where we didn’t want multiple tabs to open as and when one clicked on a search result, and we wanted the search result item to open in the main content tree instead.
This would enable the content authors to locate items in the item tree and create subitems / manipulate them. Even though the bucket search results page does allow creation of subitems (provided insert options are set), this provides a simpler means of browsing through subitems in a more effective manner.

To be able to achieve this, we need a config update and corresponding code update.

Code:

using Sitecore;
using Sitecore.Buckets.Pipelines.UI.LaunchResultPipeline;
using Sitecore.Data;
using Sitecore.Data.Items;
using System;

namespace MySite.SitecoreProcessors
{
    public class LaunchSitecoreResultMainWindow : LaunchSitecoreResult
    {
        protected override void LaunchResult(LaunchResultArgs args)
        {
            if (!string.IsNullOrEmpty(args.IndexableId))
            {
                ID itemId = ID.Parse(args.IndexableId);
                Item myItem = Context.Database.GetItem(itemId);

                if (myItem != null)
                {
                    Context.ClientPage.SendMessage(this, String.Concat(
                        new object[] {"item:load(id=", myItem.ID, ",language=", myItem.Language, ",version=", myItem.Version, ")"}));
                }
            }
        }
    }
}

Here’s the config update:

    <sitecore>
      <processors>
        <uiLaunchResult>
          <processor desc="sitecore">
            <patch:attribute name="type">MySite.SitecoreProcessors.LaunchSitecoreResultMainWindow, MySite</patch:attribute>
          </processor>
        </uiLaunchResult>
      </processors>
    </sitecore>

So now, when we search for an item within a bucket, and click on a search result, it will open in the main content editor.

2015-03-16_022715

2015-03-16_022957

Advertisements

3 thoughts on “Open items from bucket search in main content tree in Sitecore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s