use of org.craftercms.engine.navigation.NavItem in project engine by craftercms.
the class NavBreadcrumbBuilderImpl method getBreadcrumb.
@Override
public List<NavItem> getBreadcrumb(String url, String root, Converter<SiteItem, NavItem> itemConverter) {
if (itemConverter == null) {
itemConverter = defaultItemConverter;
}
List<NavItem> breadcrumb = new ArrayList<>();
String breadcrumbUrl = extractBreadcrumbUrl(url, root);
String[] breadcrumbUrlComponents = breadcrumbUrl.split("/");
String currentUrl = root;
for (String breadcrumbUrlComponent : breadcrumbUrlComponents) {
currentUrl = UrlUtils.concat(currentUrl, breadcrumbUrlComponent);
SiteItem siteItem = siteItemService.getSiteItem(currentUrl, processor);
if (siteItem != null) {
NavItem navItem = itemConverter.convert(siteItem);
if (navItem != null) {
navItem.setActive(url.equals(siteItem.getItem().getDescriptorUrl()));
breadcrumb.add(navItem);
}
}
}
return breadcrumb;
}
use of org.craftercms.engine.navigation.NavItem in project engine by craftercms.
the class DefaultItemConverter method convert.
@Override
public NavItem convert(SiteItem siteItem) {
NavItem navItem = null;
if (siteItem.getDom() != null) {
navItem = new NavItem();
navItem.setLabel(getNavigationLabel(siteItem));
navItem.setUrl(getNavigationUrl(siteItem));
navItem.setAttributes(getAdditionalAttributes(siteItem));
}
return navItem;
}
use of org.craftercms.engine.navigation.NavItem in project engine by craftercms.
the class NavTreeBuilderImplTest method getItemConverter.
private Converter<SiteItem, NavItem> getItemConverter() {
Converter<SiteItem, NavItem> converter = mock(Converter.class);
doAnswer((Answer<NavItem>) invocation -> {
SiteItem siteItem = (SiteItem) invocation.getArguments()[0];
NavItem navItem = new NavItem();
navItem.setLabel(siteItem.getStoreName());
navItem.setUrl(siteItem.getStoreUrl());
return navItem;
}).when(converter).convert(any(SiteItem.class));
return converter;
}
use of org.craftercms.engine.navigation.NavItem in project engine by craftercms.
the class NavTreeBuilderImplTest method testGetNavTree.
@Test
public void testGetNavTree() {
NavItem navItem = navTreeBuilder.getNavTree(ROOT_URL, -1, URL3);
assertNotNull(navItem);
assertEquals(ROOT_URL, navItem.getUrl());
assertTrue(navItem.isActive());
assertEquals(2, navItem.getSubItems().size());
assertEquals(URL1, navItem.getSubItems().get(0).getUrl());
assertFalse(navItem.getSubItems().get(0).isActive());
assertEquals(URL2, navItem.getSubItems().get(1).getUrl());
assertTrue(navItem.getSubItems().get(1).isActive());
assertEquals(1, navItem.getSubItems().get(1).getSubItems().size());
assertEquals(URL3, navItem.getSubItems().get(1).getSubItems().get(0).getUrl());
assertTrue(navItem.getSubItems().get(1).getSubItems().get(0).isActive());
}
use of org.craftercms.engine.navigation.NavItem in project engine by craftercms.
the class NavTreeBuilderImpl method getNavItem.
protected NavItem getNavItem(SiteItem siteItem, String currentPageUrl, Converter<SiteItem, NavItem> itemConverter) {
NavItem navItem = itemConverter.convert(siteItem);
if (navItem != null) {
navItem.setSubItems(getNavSubItems(siteItem, currentPageUrl, itemConverter));
navItem.setActive(isActive(currentPageUrl, siteItem.getStoreUrl()));
return navItem;
} else {
return null;
}
}
Aggregations