There is no easy way to block it in the UI. What you could do is write a custom validator for your typed model (page/block) that holds the contentarea. Below is an example on a validator implemenation that prevents users from adding a block of type "MyBlock" to the contentarea named "MainContentArea" on StandardPage.
public class StandardPageValidator : IValidate<StandardPage>
{
public IEnumerable<ValidationError> Validate(StandardPage page)
{
if (page.MainContentArea != null && page.MainContentArea.Contents.
Any(c => c.GetOriginalType().IsAssignableFrom(typeof(MyBlock))))
{
return new ValidationError[]{new ValidationError()
{
ErrorMessage = "MyBlock is not allowed in this area",
PropertyName = page.GetPropertyName<StandardPage>(p => p.MainContentArea),
Severity = ValidationErrorSeverity.Error,
ValidationType = ValidationErrorType.StorageValidation
}};
}
return Enumerable.Empty<ValidationError>();
}
}
The user experience will be that the editor will still be able to drop an instance of the block into the contentarea but when it is saved an message will appear saying tha the block is not allowed in the area. And it will not be possible to publish the change until the block is removed from the area.
Is it possible to limit which blocks that are available to choose from for specific users / groups?
You can for a shared block instance set access right on it in form edit mode (just like for pages). In admin mode/Set access rights you can also set access rights for folder (and pages/blocks)
I noticed something in the sample project.
In the SiteLogoTypeBlockControl.ascx this was specified:
[
TemplateDescriptor(
AvailableWithoutTag =false,
Tags = new [] { "Header" })] // This block control is only allowed to be dropped in an area tagged with 'Header' through its RenderSettings property
And in the Site.Master the following:
<EPiServer:PropertyPageLink="<%#PageReference.StartPage %>"PropertyName="SiteLogotype"DisplayMissingMessage="True"runat="server">
<RenderSettingsTag="Header"/>
</EPiServer:Property>
Doesn't that do what Jeroen asked about or have I misernderstood everything?
Yes that is another possible approach. With that approach it will be possible to drop the block in the area and it will be possible to save/publish the page. Then when rendered in edit mode a message will appear saying "There is no matching renderer for 'type'" and in view mode nothing will be rendered.
I think a nice thing to have would be something like the possiblity to not show plugins via creating a null plugindescriptor.
This would be great both for all sorts of new stuff in 7 like blocks but also for gadgets.
The best thing would ofcourse be if it was possible to manage which gadgets, blocks, plugins etc thats available for specific users/groups from admin mode. And that includes all the builtin gadgets etc not only the stuff we create ourselves.
Actually, as far as I see there is much easier way: decorate contentarea with [AvailableContentTypes(Include = new[] { typeof(BlockType), })]
And customer would not be able to save a page, if there is wrong blocks added
Only classes can be decorated with AvailableContentTypes attribute.
You should use [AllowedTypes(typeof(...))] for your ContentArea property.
More info: http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/Restriction-of-content-types-in-properties/
Maybe you can get this to Work?
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=81335&epslanguage=en
Hi,
How can I restrict the block types that can be added to a contentarea?
Thanks in advanced,
Jeroen Slor