4

In the Experience Editor, there is a breadcrumbs-type Navigation Bar that allows editors to navigate the Sitecore tree:

Image of breadcrumbs in Experience Editor

However, some non-page items show up in the drop-down lists of items which causes confusion because they can't be edited in Experience Editor.

How do I limit the items that are returned in those lists?

1 Answer 1

7

Clicking the > icon calls the Sitecore.ExperienceEditor.Speak.Ribbon.Requests.Breadcrumb.GetChildItems.ProcessRequest() method which returns a model containing a List<BreadcrumbItem>. That list is then rendered to the drop-down in the Experience Editor. By replacing the GetChildItems class with a custom class, you can return whatever items you like.

You'll need two things:

A Custom Class

You'll need references to Sitecore.ExperienceEditor.Speak and Sitecore.ExperienceEditor.Speak.Ribbon to build this class.

using System.Collections.Generic;
using System.Linq;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.ExperienceEditor.Speak.Ribbon.Requests.Breadcrumb;
using Sitecore.ExperienceEditor.Speak.Server.Contexts;
using Sitecore.ExperienceEditor.Speak.Server.Requests;
using Sitecore.ExperienceEditor.Speak.Server.Responses;
using Sitecore.Globalization;

namespace Test.Services.SpeakRequests
{
    /// <summary>
    /// This class is decompiled from Sitecore.ExperienceEditor.Speak.Ribbon.Requests.Breadcrumb.GetChildItems and reproduced here to introduce template filtering
    /// </summary>
    public class BreadcrumbGetChildItems : PipelineProcessorRequest<ItemContext>
    {
        private readonly IList<ID> _HiddenTemplateIds = new List<ID>
                                                        {
                                                            GlobalConstants.BucketTemplateId
                                                        };

        public override PipelineProcessorResponseValue ProcessRequest()
        {
            if (RequestContext.Item == null)
            {
                return new PipelineProcessorResponseValue
                {
                    AbortMessage = Translate.Text("The target item could not be found.")
                };
            }
            var breadcrumbItems = new List<BreadcrumbItem>();
            // This .Where() clause is the only difference between the decompiled code and this custom class (besides the _HiddenTemplateIds list it references, of course)
            foreach (Item child in RequestContext.Item.Children.Where(c => !_HiddenTemplateIds.Contains(c.TemplateID)))
            {
                breadcrumbItems.Add(new BreadcrumbItem(child, RequestContext.DeviceItem));
            }
            return new PipelineProcessorResponseValue
            {
                Value = breadcrumbItems
            };
        }
    }
}

A Config Patch

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
    <sitecore>
        <sitecore.experienceeditor.speak.requests>
            <request name="ExperienceEditor.Breadcrumb.GetChildItems" type="Test.Services.SpeakRequests.BreadcrumbGetChildItems, Test.Services"
                           patch:instead="*[@name='ExperienceEditor.Breadcrumb.GetChildItems']" />
        </sitecore.experienceeditor.speak.requests>
    </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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