/// <summary> /// Returns the closest parent to the start page of the given page. /// </summary> /// <remarks> /// Start Page /// - About Us (This is the section) /// - News /// News 1 (= contentLink parameter) /// </remarks> /// <param name="contentLink">The content you want to find the section for</param> /// <returns>The parent page closes to the start page, or the page referenced by the contentLink itself</returns> private IContent GetSection(ContentReference contentLink) { var currentContent = ContentLoader.Get <IContent>(contentLink); if (currentContent.ParentLink != null && currentContent.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage)) { return(currentContent); } // Loop upwards until the parent is start page or root return(ContentLoader.GetAncestors(contentLink) .OfType <PageData>() .SkipWhile(x => x.ParentLink == null || !x.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage)) .FirstOrDefault()); }
public ContentArea CreateRelatedProductsContentArea(EntryContentBase catalogContent, string associationType) { IEnumerable <Association> associations = LinksRepository.GetAssociations(catalogContent.ContentLink); ContentArea relatedEntriesCA = new ContentArea(); List <EntryContentBase> relatedEntires = Enumerable.Where(associations, p => p.Group.Name.Equals(associationType)) .Select(a => ContentLoader.Get <EntryContentBase>(a.Target)).ToList(); foreach (var relatedEntire in relatedEntires) { ContentAreaItem caItem = new ContentAreaItem(); caItem.ContentLink = relatedEntire.ContentLink; relatedEntriesCA.Items.Add(caItem); } return(relatedEntriesCA); }
public FashionProductViewModel CreateFashionProductViewModel(FashionProductContent currentContent, HomePage currentPage) { var model = new FashionProductViewModel(currentContent); InitializeProductViewModel(model); // get delivery and returns from the start page var startPage = ContentLoader.Get <HomePage>(ContentReference.StartPage); model.DeliveryAndReturns = startPage.Settings.DeliveryAndReturns; model.SizeGuideReference = GetSizeGuide(currentContent); model.SizeUnit = currentContent.SizeUnit; model.SizeType = currentContent.SizeType; return(model); }
private IEnumerable <ContentReference> GetBlocks(ContentReference descendent, CultureInfo existingCulture, CultureInfo newCulture) { var page = ContentLoader.Get <ContentData>(descendent, newCulture); foreach (var property in page.Property) { if (property.Value is ContentArea contentArea) { foreach (var item in contentArea.Items) { if (ContentLoader.TryGet(item.ContentLink, existingCulture, out BlockData _)) { yield return(item.ContentLink); } } } } }
public ContentArea CreateRelatedProductsContentArea(EntryContentBase catalogContent, string associationType) { IEnumerable <Association> associations = LinksRepository.GetAssociations(catalogContent.ContentLink); var relatedEntires = associations.Where(p => p.Group.Name.Equals(associationType)) .Where(x => x.Target != null && x.Target != ContentReference.EmptyReference) .Select(x => ContentLoader.Get <EntryContentBase>(x.Target)); var relatedEntriesCa = new ContentArea(); foreach (var relatedEntire in relatedEntires) { ContentAreaItem caItem = new ContentAreaItem(); caItem.ContentLink = relatedEntire.ContentLink; relatedEntriesCa.Items.Add(caItem); } return(relatedEntriesCa); }
/// <summary> /// Index content for all langauges /// </summary> /// <param name="content"></param> /// <param name="alias"></param> public virtual void IndexContentEveryLanguage(IContent content, string alias = null) { VulcanHelper.GuardForNullAlias(ref alias); if (content is ILocalizable localizable) { foreach (var language in localizable.ExistingLanguages) { var client = GetClient(language, alias); client.IndexContent(ContentLoader.Get <IContent>(content.ContentLink.ToReferenceWithoutVersion(), language)); } } else { var client = GetClient(CultureInfo.InvariantCulture, alias); client.IndexContent(content); } }
protected virtual IList GetPagesCollection(Func <IEnumerable <ContentReference> > retrieveMethod, Type itemType) { Func <IEnumerable <IContent> > loadPages = () => retrieveMethod().Select(x => ContentLoader.Get <IContent>(x)); var result = GetPagesCollection(loadPages, itemType); return(result); }
protected IEnumerable <EntryContentBase> GetRelatedContent() { if (CurrentData == null) { return(Enumerable.Empty <EntryContentBase>()); } var allAssociations = LinkRepository.Service.GetAssociations(CurrentData.ContentLink); var relatedItems = allAssociations.Where(a => a.Group.Name == GroupName).Select(a => ContentLoader.Get <EntryContentBase>(a.Target)); var currentMarket = CurrentMarket.GetCurrentMarket(); return(ForVisitor(() => relatedItems.Where(i => !i.MarketFilter.Contains(currentMarket.MarketId)))); }
public object GetValue(IContentData contentData, PropertyInfo property) { // define if property is required var requiredAnnotation = property.GetAttribute <RequiredAttribute>(); // get annotation attribute var annotation = property.GetAnnotation <CmsReferenceAttribute>(); // get reference property name set by attribute or default var referencePropertyName = annotation.LinkFieldName ?? property.Name + "Link"; // lookup reference property var referenceProperty = contentData.Property[referencePropertyName] as PropertyPageReference; if (referenceProperty != null) // if reference property found { // get link to a referenced page var link = referenceProperty.ContentLink; if (!ContentReference.IsNullOrEmpty(link)) // and if it's not empty { // load referenced page and cast it to the target property type. var result = ContentLoader.Get <PageData>(link).Cast(property.PropertyType); if (result != null) { return(result); } } } if (requiredAnnotation == null) // if property is not marked as required { return(null); } // otherwise get error message string errorMessageFormat; if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessageResourceName)) { errorMessageFormat = LocalizationService.GetString(requiredAnnotation.ErrorMessageResourceName); } else if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessage)) { errorMessageFormat = requiredAnnotation.ErrorMessage; } else { errorMessageFormat = LocalizationService.GetString("EPiProperties/PropertyRequiredFormat", "Required property '{0}' is not properly set on the page #{1} of type '{2}'. "); } var content = contentData as IContent; if (content != null) { var contentType = ContentTypeRepository.Load(content.ContentTypeID); var errorMessage = string.Format(errorMessageFormat, property.Name, content.ContentLink.ID, contentType.DisplayName); throw new ApplicationException(errorMessage); } else { throw new ApplicationException(string.Format(errorMessageFormat, property.Name, "?", "?")); // TODO } }