A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Anders Hattestad
Jun 22, 2012
  5357
(0 votes)

Heads up when creating a Property that connects to other pages

There are times you want to connect on of your pages to other pages of certain types.  It could be some meta data structure or it could be relevant pages. There are other options out there like  FilteredPageReference  but if you want to make your own this is a blog post about what you should consider.

My first idea was to make this I just stored the id’s of the pages in a list. And implemented the IReferenceMap so I could handle import/export and hopeful the warning you get when you try to delete a page when a page is in use in an other page. But strangely the soft links doesn't use the IReferenceMap when it tries to find connected pages. Very strange. This should be fixed I think Trist fjes

The code that is run behind the scene to update the table with all pages that referrers to other pages is inside the LazyIndexer where this code is executed for each page

sealed class LazyIndexer
  1. foreach (PropertyData current2 in current.Property)
  2. {
  3.     if (!PageDB.IsIdentityData(current2.Name) && !current2.IsNull)
  4.     {
  5.         if (current2 is PropertyPageReference)
  6.         {
  7.             LazyIndexer.HandleRemotePropertyPageReference(current2 as PropertyPageReference, pageReference, softLinkCollection);
  8.         }
  9.         else
  10.         {
  11.             if (current2 is PropertyUrl)
  12.             {
  13.                 LazyIndexer.HandlePropertyUrl(current2 as PropertyUrl, pageReference, softLinkCollection);
  14.             }
  15.             else
  16.             {
  17.                 if (current2 is PropertyXhtmlString)
  18.                 {
  19.                     LazyIndexer.HandleXhtmlString(current2 as PropertyXhtmlString, softLinkCollection, current);
  20.                 }
  21.             }
  22.         }
  23.     }

as you can se there is no reference to IReferenceMap here at all. The code that is run inside here is

  1. private static void HandleXhtmlString(PropertyXhtmlString prop, SoftLinkCollection softLinks, PageData page)
  2. {
  3.     if (prop is PropertyLinkCollection || !LazyIndexer.IsSearchable(page.PageTypeID, prop))
  4.     {
  5.         HtmlParser htmlParser = new HtmlParser(HttpUtility.HtmlDecode(prop.ToRawString()), false);
  6.         LazyIndexer.IndexLinksAndImages(softLinks, htmlParser);
  7.         LazyIndexer.IndexTableBackgrounds(softLinks, htmlParser);
  8.     }
  9. }

So my property needs to inherit from PropertyLinkCollection or have to be searchable and inherit from PropertyXhtmlString.  and it needs to save the connected pages as hrefs.

So when one make a property that connects pages to each other and you want to ensure that the warning is given you have to make your property store links to those other pages.  So if one inherits from PropertyLinkCollection one could easy add the property ListOfPageIds

  1. public class PropertySelectManyOf : PropertyLinkCollection
  2. {
  3.     public string ListOfPageIds
  4.     {
  5.         get
  6.         {
  7.             var result = "";
  8.             foreach (var link in this.Links)
  9.             {
  10.                 string linkUrl = string.Empty;
  11.                 PermanentLinkMapStore.TryToMapped(link.Href, out linkUrl);
  12.                 if (!string.IsNullOrEmpty(linkUrl))
  13.                 {
  14.                     PageReference pageRef = PageReference.ParseUrl(linkUrl);
  15.                     if (!PageReference.IsNullOrEmpty(pageRef))
  16.                     {
  17.                         if (result != "")
  18.                             result += ",";
  19.                         result += pageRef.ToString();
  20.                     }
  21.                 }
  22.             }
  23.             return result;
  24.         }
  25.         set
  26.         {
  27.             var result = new LinkItemCollection();
  28.             string ids = value;
  29.             foreach (string id in ids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
  30.             {
  31.                 var i = PageReference.EmptyReference;
  32.                 if (PageReference.TryParse(id, out i))
  33.                 {
  34.                     try
  35.                     {
  36.                         var page = EPiServer.DataFactory.Instance.GetPage(i);
  37.                         var link = new LinkItem();
  38.                         link.Href = page.LinkURL;
  39.                         link.Text = page.PageName;
  40.                         result.Add(link);
  41.                     }
  42.                     catch { }
  43.                 }
  44.             }
  45.             this.Value = result;
  46.         }
  47.     }

if one had an existing property that had stored these as a list of id’s its easy to add

Code Snippet
  1. public override void LoadData(object value)
  2. {
  3.     try
  4.     {
  5.         base.LoadData(value);
  6.     }
  7.     catch
  8.     {
  9.         ListOfPageIds = "" + value;
  10.     }
  11. }

so one can convert on the fly from list of ids to LinkCollection. you do have to resave all the pages thou, to update the mapping table.

When I now tries to delete my connected page I get this error

image

So it is working when you inherit from PropertyLinkCollection

Jun 22, 2012

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP: Learning Optimizely Just Got Easier: Introducing the Optimizely Learning Centre

On the back of my last post about the Opti Graph Learning Centre, I am now happy to announce a revamped interactive learning platform that makes...

Graham Carr | Jan 31, 2026

Scheduled job for deleting content types and all related content

In my previous blog post which was about getting an overview of your sites content https://world.optimizely.com/blogs/Per-Nergard/Dates/2026/1/sche...

Per Nergård (MVP) | Jan 30, 2026

Working With Applications in Optimizely CMS 13

💡 Note:  The following content has been written based on Optimizely CMS 13 Preview 2 and may not accurately reflect the final release version. As...

Mark Stott | Jan 30, 2026

Experimentation at Speed Using Optimizely Opal and Web Experimentation

If you are working in experimentation, you will know that speed matters. The quicker you can go from idea to implementation, the faster you can...

Minesh Shah (Netcel) | Jan 30, 2026

How to run Optimizely CMS on VS Code Dev Containers

VS Code Dev Containers is an extension that allows you to use a Docker container as a full-featured development environment. Instead of installing...

Daniel Halse | Jan 30, 2026

A day in the life of an Optimizely OMVP: Introducing Optimizely Graph Learning Centre Beta: Master GraphQL for Content Delivery

GraphQL is transforming how developers query and deliver content from Optimizely CMS. But let's be honest—there's a learning curve. Between...

Graham Carr | Jan 30, 2026