Try our conversational search powered by Generative AI!

Restrict block types in contentarea

Vote:
 

Hi,

How can I restrict the block types that can be added to a contentarea?

Thanks in advanced,

 

Jeroen Slor

#63002
Nov 06, 2012 19:35
Vote:
 

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.

#63007
Nov 07, 2012 8:09
Vote:
 

Is it possible to limit which blocks that are available to choose from for specific users / groups?

#63009
Nov 07, 2012 8:33
Vote:
 

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)

 

#63011
Nov 07, 2012 8:42
Vote:
 

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?

#63094
Nov 09, 2012 0:00
Vote:
 

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. 

#63097
Nov 09, 2012 5:26
Vote:
 

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.

#63101
Edited, Nov 09, 2012 8:41
Vote:
 

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

#76352
Oct 22, 2013 18:04
Vote:
 

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/

#80960
Edited, Feb 06, 2014 8:06
Vote:
 

Valdis, the AllowedTypes comes in 7.5, this is a post in the 7 forum.

#80964
Feb 06, 2014 8:56
Vote:
 

Oh, really. Then sorry - didn't look at version..

#80971
Feb 06, 2014 9:22
Vote:
 

Maybe you can get this to Work?

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=81335&epslanguage=en

#81625
Feb 21, 2014 7:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.