I'm trying to restrict a block to only be allowed to be created on a specific page type, in a specific contentarea on that page type. Is this possible? If not both, then perhaps restricting to a certain page type is possible?
I know it's possible to set which block types are allowed in a contentarea, but i don't want to go around changing settings for every single contentarea to restrict this one block type. Also using IValidate seems to be an option, but i would like to avoid using it. For the user experience it would be better not to show the block type at all where it's not supposed to be created.
Thanks a lot!
The block can be created from different places in the CMS UI. E.g. block widget or content area directly. Therefore, I think you have to implement restriction in you code from preventing Editor accidently drags unwanted blocks into the content area regardless.
It depends on what you're after. If you want to filter the list of available blocks for content area or specific site, it is doable.
Can this blocktype be used multiple times on that page? If not, you could make it a property on the page and hide the block from editors to be used in content areas
I've had something similar before.
You can set the block as 'AvailableInEditMode = false' and then set the allowed types for your content area to that block.
The next part is a bit of a compromise...
Last I checked, the ContentArea won't have a link for you to create the block, nor can you create one in the sidebar (due to the availability) HOWEVER, if you add an instance of the block by default (programmatically, using code), then you'll get the link in the content area for adding more.
Hopefully, this helps get you part of the way there...