PageProviders and DDS, a match from heaven…
I’m working on a pet project where I’m trying to show community entities as a tree structure in EPiServer.
But then I tried to just show on structure bellow an other page using PageProviders.
To make a PageProvider you need both a unique number inside the page provider, and a guid that is unique across all elements. This is a perfect match with the DSS’s Identity that both have a long and a guid inside.
So what I did was that I made myself a mapping table using the DDS Id as the id and guid for my page provider.
The properties in my DDS table is this:
and my episerver.config have these elements defined. Where should we get the page structure from, and where should they be displayed
- <pageProvider>
- <providers>
- <add name="Club1" type="Itera.PageProviders.SubStructurPageProvider, EPiServer.Templates.RelatePlus"
- entryPoint="43"
- GetChildrenFrom="6"/>
- </providers>
- </pageProvider>
The first method I need to implement is the one that returns page references for one page reference.
- protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID)
- {
- if (pageLink.CompareToIgnoreWorkID(base.EntryPoint))
- {
- var pages = EPiServer.DataFactory.Instance.GetChildren(GetChildrenFrom,
- new LanguageSelector(languageID));
- return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
- }
- else
- {
- var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
- if (item != null)
- {
- var pages = EPiServer.DataFactory.Instance.GetChildren(item.ContentPage,
- new LanguageSelector(languageID));
- return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
- }
- }
- return new PageReferenceCollection();
- }
I call the Ensure method and that stores the page references using the DDS. And the use the Id in the DDS table to make the “new” page link.
- public static PageReferenceCollection Ensure(PageDataCollection pages, string providerKey,string parentPageLink)
- {
- PageReferenceCollection result = new PageReferenceCollection();
- var query = from item in Store.Items<SubStructurIDs>() where
- item.ProviderKey == providerKey &&
- item.ParentPageLink == parentPageLink
- select item;
- var hash = new Dictionary<int, SubStructurIDs>();
- foreach (var item in query)
- {
- hash.Add(item.ContentPage.ID, item);
- }
- foreach (var page in pages)
- {
- if (hash.ContainsKey(page.PageLink.ID))
- {
- result.Add(hash[page.PageLink.ID].ThisPageLink);
- hash.Remove(page.PageLink.ID);
- }
- else
- {
- var newItem = new SubStructurIDs();
- newItem.ContentPage = page.PageLink;
- newItem.ParentPageLink = parentPageLink;
- newItem.ProviderKey = providerKey;
- Store.Save(newItem);
- result.Add(newItem.ThisPageLink);
- }
- }
- if (hash.Count > 0)
- {
- //Need to delete, or in other lang
- }
- return result;
- }
The I need to implement 2 functions, one where we have the page link and the find the guid, and one that have the guid and needs to find the page Link. These to are pretty much alike, and one looks like this
- protected override Uri ResolveLocalPage(Guid pageGuid, out PageReference pageLink)
- {
- var item = SubStructurIDs.GetItem(pageGuid, ProviderKey);
- if (item != null)
- {
- pageLink = item.ThisPageLink;
- return CreateUri(pageLink, item);
- }
- pageLink = PageReference.EmptyReference;
- return null;
- }
Then we need to return a page
- protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector languageSelector)
- {
- var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
- if (item != null)
- {
- PageData org = EPiServer.DataFactory.Instance.GetPage(item.ContentPage, languageSelector);
- if (org != null)
- {
- org = org.CreateWritableClone();
- org.PageLink = pageLink;
- org.ParentLink = PageReference.Parse(item.ParentPageLink);
- org.PageGuid = item.Id.ExternalId;
- return org;
- }
- }
- return null;
- }
And then we are good to go.
Comments