private NavigationItem CreateNavigationItem(Item item, int level, int maxLevel = -1) { return new NavigationItem { Item = item, Url = (item.IsDerived(Templates.Link.ID) ? item.LinkFieldUrl(Templates.Link.Fields.Link) : item.Url()), Target = (item.IsDerived(Templates.Link.ID) ? item.LinkFieldTarget(Templates.Link.Fields.Link) : ""), IsActive = this.IsItemActive(item), Children = this.GetChildNavigationItems(item, level + 1, maxLevel) }; }
public virtual string GetPageLinkOrDefault(Item contextItem, ID field, Item defaultItem) { Assert.ArgumentNotNull(defaultItem, nameof(defaultItem)); try { return this.GetPageLink(contextItem, field); } catch (Exception ex) { Log.Warn(ex.Message, ex, this); return defaultItem.Url(); } }
public void GetPageLinkOrDefaultShouldReturnDefault(Item item,ID id, Item defaultItem) { var accountSettingsService = Substitute.ForPartsOf<AccountsSettingsService>(); accountSettingsService.When(x => x.GetPageLink(item, id)).DoNotCallBase(); accountSettingsService.GetPageLink(Arg.Any<Item>(), Arg.Any<ID>()).Returns(x => { throw new Exception(); }); var result = accountSettingsService.GetPageLinkOrDefault(item, id, defaultItem); result.Should().Be(defaultItem.Url()); }
private NavigationItem CreateNavigationItem(Item item, int level, int maxLevel = -1) { var targetItem = item.IsDerived(Templates.Link.ID) ? item.TargetItem(Templates.Link.Fields.Link) : item; return new NavigationItem { Item = item, Url = item.IsDerived(Templates.Link.ID) ? item.LinkFieldUrl(Templates.Link.Fields.Link) : item.Url(), Target = item.IsDerived(Templates.Link.ID) ? item.LinkFieldTarget(Templates.Link.Fields.Link) : "", IsActive = this.IsItemActive(targetItem ?? item), Children = this.GetChildNavigationItems(item, level + 1, maxLevel), ShowChildren = !item.IsDerived(Templates.Navigable.ID) || item.Fields[Templates.Navigable.Fields.ShowChildren].IsChecked() }; }