AllowedTypes - Extending functionality

Vote:
 

Hi everybody.

I have a site which contains Page -> Blocks (Level 1) -> Blocks (Level 2)
And it works quite well - however, I'm running into a situation where I'd like to extend AllowedTypes for a block ContentArea.

I've seen that AllowedTypes are basically just an ValidateAttribute, so I should be able to build my own additional validation as well to determine valid blocks;
however - that means the blocks that are invalid according to my logic are still shown in the cms editor when creating a new block for a Content Area.

So I'm looking for whether it's possible to extending/overrule the function that lists Allowed blocks or extending the AllowedTypes IsValid functionality?

Basically - what I'm after is that some Block types are only valid on some Level 2 if they're on a specific Page. And if I'm going to solve that using AllowedType, I'll need to duplicate my Level 1 blocks or start assigning the AllowedTypes programmatically.
So I'm thinking simply adding an additional validation would be easiest, *if* I could also remove them from the shown list in cms edit.

#176342
Mar 16, 2017 12:56
Vote:
 

I have never tried the approach but you might be able to use virtual roles (http://world.episerver.com/documentation/Class-library/?documentId=cms/8/1B4BB538):

  • Set permissions on your content type to only allow access to a new virtual role that you create
  • On request, your virtual role can check the current request content and return true/false depending on whether you are on a level 1 or 2 page

It may work, let me know how you get on!

#176426
Edited, Mar 19, 2017 23:28
Vote:
 

Thank you for the suggestion - I took a look at the virtual roles and on the surface it does seem to be possible going down that route.

I did however begin to struggle with context and trying to determine whether I was on the "allowed pages" when validating the role, so I decided against it for performance issues. 

So for now - I'll handle it in the descriptions and by making sure the code doesn't crash if invalid combinations are used (blocks require specific page data to exists and so on).


Thank you anyway for the suggestion.

#176548
Mar 21, 2017 11:19
* 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.