SaaS CMS has officially launched! Learn more now.

Per Nergård
Apr 2, 2019
  3298
(6 votes)

AllowedTypes for LinkItem collection

The other day I heard a discussion about a possible requirement for only allowing specific pages in a LinkItem collection.  My first thought was to use a ContentArea property in combination with the AllowedTypes attribute but for some reason the possiblity to have external links was needed.

I googled a bit but I only found a post where a custom validation class handled validation of max number of items in a LinkItemCollection, you can read Allan Thraens blog post here.

It seemed like a clean and simple approach so I decided to do a variant that is similiar to AllowedTypes for ContentArea and ContentReference properties.

My solution is a simple validation attribute that takes an array of types that should be allowed to add to a LinkItemCollection property. The attribute ignores linkitems that are not Episerver content.If an Epierver content (page,image) is added to the LinkItemCollection and the underlying type is not inte the allowed types array a error message is displayed and publishing of the page is blocked.

You can find the coder over at my gist.

Apr 02, 2019

Comments

Praful Jangid
Praful Jangid Apr 3, 2019 02:46 PM

Good one, I was thinking to implement this requirement. :) 

One of my team mate had this requirement.

Thanks for simplifying that for us.

Per Nergård
Per Nergård Apr 13, 2019 12:47 PM

Thanks! Glad it could be of use.

John Ligtenberg
John Ligtenberg Sep 18, 2020 05:15 PM

Very useful. I changed the code to support inherited types, see my gist.

Please login to comment.
Latest blogs
Optimizely release SaaS CMS

Discover the future of content management with Optimizely SaaS CMS. Enjoy seamless updates, reduced costs, and enhanced flexibility for developers...

Andy Blyth | Jul 17, 2024 | Syndicated blog

A day in the life of an Optimizely Developer - London Meetup 2024

Hello and welcome to another instalment of A Day In The Life Of An Optimizely Developer. Last night (11th July 2024) I was excited to have attended...

Graham Carr | Jul 16, 2024

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024