Restricting a Block on all content areas

Vote:
 

Hi

I have a SliderContainerBlock and an SliderItemBlock.

I am able to restirct the items which can be added into the SliderContainerBlock by using the following

[AllowedTypes(typeof(SliderItemBlock))]
public virtual ContentArea SliderItemBlocksContentArea { get; set; }

which works fine. 

However I also want that the SliderItemBlock cannot be added to any other content area on the site. 

[SiteContentType(GUID = "117a95a1-86ed-4dd7-b70d-a2736482734d",
GroupName = Global)]
[AvailableContentTypes(Availability.Specific, Include = new[] { typeof(SliderContainerBlock)}]
public class SliderItemBlock : SiteBlockData

using the following attribute does not seem to work.

[AvailableContentTypes(Availability.Specific, Include = new[] { typeof(SliderContainerBlock)}]

Is it possible to restirct a block in all content areas and only allow them in the ones I want. I do not want to go to every content area on the site and specifcy the allowed types.

Kind regards

Sandeep

#188924
Mar 07, 2018 3:20
Vote:
 

Our solution is to add an interface to the block:

public class SliderBlock : INotAvailableContent {}

The interface and descriptor:

public interface INotAvailableContent { }

[UIDescriptorRegistration]
public class NotAvailableContentDescriptor : UIDescriptor<INotAvailableContent> { }

The ContentArea defintion:

[AllowedTypes(RestrictedTypes = new[] { typeof(INotAvailableContent) })]
public virtual ContentArea MainContentArea { get; set; }

Now you can easy add INotAvailableContent for ContentAreas and blocks to avoid them.

#188933
Mar 07, 2018 10:36
Vote:
 

Thanks Empa.

I am presuming I would still need to tag all my content area fields with the attribute

[AllowedTypes(RestrictedTypes = new[] { typeof(INotAvailableContent) })]

It is certainly less work than excluding each block individualy but would have been nice to have something which we could add onto the SliderBlockItem class to just exlude it from all content area apart from the one we exclusively specify.

Kind regards

Sandeep

#188934
Mar 07, 2018 10:51
Vote:
 

Yes, I understand. But this was the best solution we came up with.

#188936
Mar 07, 2018 11:07
Vote:
 

Thank you very much. As mentioned still less work than adding each one manually.

Just to implement something when starting the project so that it is not a lot of work later.

Kind regards

Sandeep

#188937
Mar 07, 2018 11:13
Vote:
 

It seems like doing

[ContentType(AvailableInEditMode = false, GUID = "D8D1795B-1990-498E-A6A7-C5DF238E150A")]

on your block type does the trick? Is that not a simpler way to do it?

#195178
Jul 17, 2018 9:23
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.