Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.

 

Restrict Content Area only to add Links

Vote:
 

How to Restrict Content Area only to add Links?

#226457
Aug 13, 2020 12:00
Vote:
 

What do you mean?

Allow links to pages, but not adding blocks?

#226464
Aug 13, 2020 13:16
Vote:
 

Hi Tanvi,

Can you please explain it more?

Like -do you want to add a specific block in the ContentArea?

#226467
Aug 13, 2020 13:19
Vote:
 

Yes I want to add only Links to Pages in the ContentArea 

#226468
Aug 13, 2020 13:22
Vote:
 

ok, then I think AllowedTypes is the best way to do this-

[AllowedTypes(new []{ typeof(YourPageType) })]
public virtual ContentArea Gallery { get; set; }
#226469
Edited, Aug 13, 2020 13:28
Vote:
 

You have several options.

1. Add an AllowedTypes attribute to your property

[AllowedTypes(typeof(PageData))]


2. Use LinkItemCollection instead of ContentArea

 public virtual LinkItemCollection MyLinkProperty{ get; set; }


3. Use List of ContentReference

[AllowedTypes(typeof(PageData))]
public virtual IList<ContentReference> MyContentListProperty{ get; set; }
#226470
Edited, Aug 13, 2020 13:29
Vote:
 

I'm using ContentArea as I want only specific page links. I dont want to add links for all types of pages.

Can u suggest any code which can restrict the pagetype links to only specific ones in LinkItemCollection?

#226474
Aug 13, 2020 13:35
Vote:
 

If you are going to use LinkItemCollection, have a look at this:

https://world.episerver.com/blogs/Per-Nergard/Dates/2019/3/allowedtypes-for-linkitem-collection/

#226476
Aug 13, 2020 13:37
Vote:
 

Hi Tanvi,

Please use `Restriction based on base classes and interfaces` to restrict the page and block type contents:

https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/Property-types/Restricting-content-types-in-properties/

#226479
Aug 13, 2020 14:55
Vote:
 

I tried [AllowedTypes(typeof(PageData))] but this is allowing the entire pagetype.

I want it to be in form of links. [AllowedTypes(typeof(ContentReference))] is not working.

Is there any other way to add ContentReference in the ContentArea

#226482
Aug 13, 2020 16:59
Vote:
 

Tanvi, please pass the page types that you want to include in allowed types. Like below ex-

[AllowedTypes(new []{ typeof(YourPageType A), typeof(YourPageType B),
typeof(YourPageType C)})]
public virtual ContentArea Gallery { get; set; }
#226484
Aug 13, 2020 17:52
Vote:
 

I'm not what rules you need, but using IValidate lets you be very specific, if restricting by page type is not enough. You could only allow links to pages with a name starting with the letter «C» or pages that are created Friday after 5PM. Or anything else you may think of.

https://gist.github.com/fredrikhaglund/44d494d04e2ffd4e8cbd

#226509
Aug 14, 2020 4:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.