Search in sources :

Example 1 with BreadcrumbItem

use of org.onehippo.forge.breadcrumb.om.BreadcrumbItem in project hippo by NHS-digital-website.

the class CustomBreadcrumbProvider method addURLBasedParentItems.

@Override
protected void addURLBasedParentItems(final List<BreadcrumbItem> items, final HippoBean currentBean, final ResolvedSiteMapItem currentSmi, final ResolvedSiteMapItem deepestExpandedmenuItemSmi, final HstRequest request) {
    final String ancestorPath = deepestExpandedmenuItemSmi.getPathInfo();
    final String currentPath = currentSmi.getPathInfo();
    if (currentPath.startsWith(ancestorPath)) {
        String trailingPath = currentPath.substring(ancestorPath.length());
        if (trailingPath.startsWith("/")) {
            trailingPath = trailingPath.substring(1);
        }
        if (trailingPath.endsWith("/_index_")) {
            trailingPath = trailingPath.substring(0, trailingPath.indexOf("/_index_"));
        }
        int steps = trailingPath.split("/").length;
        HippoBean currentItemBean = currentBean;
        for (int i = 0; i < steps; i++) {
            BreadcrumbItem item = getBreadcrumbItem(request, currentItemBean);
            if (item != null) {
                items.add(item);
            }
            currentItemBean = currentItemBean.getParentBean();
        }
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) BreadcrumbItem(org.onehippo.forge.breadcrumb.om.BreadcrumbItem)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 BreadcrumbItem (org.onehippo.forge.breadcrumb.om.BreadcrumbItem)1