Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Bug: AllowedTypes doesn't seem to work by interface


I have a property with an allowed type restriction:

    GroupName = SystemTabNames.Content,
    Order = 300)]
[AllowedTypes(new[] { typeof(IListPage) })]
public virtual PageReference ListPage { getset; }

Don't get any code errors and all seems fine until I actually try and set the content in the editor, when it just hangs on content selection. Works fine if I remove it.

I could maybe look to create an abstract class that inherits from PageData and maybe that would work, but that then enforces an inheritance hierarchy that I don't actually want. In some ways it's a bit of a shame there is no IPageData interface that my interface could inherit from.

Jun 05, 2014 12:11

I should point out I've already check that this interface is only applied to objects that inherit from PageData.

And the reason for not using a base class is I want to be able to do something like this:

class BasePage : PageData

class StandardPage : BasePage
class FeaturePage : BasePage class NewsListPage : StandardPageIListPage class PromotionListPage : FeaturePageIListPage

Where IListPage is segregating a specific piece of functionality, but doesn't then enforce inheritance of extra unwanted properties.

Jun 05, 2014 12:17

My guess is that the type of interface you send in is not a page model, i.e. it does not inherit from IContentData which the GetChildren method needs in order to list the children of the root page. Why, I don't know though.

And you do get errors if you watch the network tab of the Chrome developer tools.


Edited, Jul 01, 2014 20:42

AllowedTypes doesn't work with base classes either. So there seems to be something that isn't working correctly.

Jul 02, 2014 0:38

I was using the following to restrict types in my ContentAreas, just had to rename it to AvailableContentAreaTypesAttribute now due to naming conflict with AvailableContentTypes in EPiServer 7.5.

It works with interfaces aswell.

**Note I have also updated the contentArea.Contents to contentArea.Items.Select(item=>item.GetContent())

As the Contents property which used to return the actual IContent items is no obsolete in 7.5 and the Items property returns ContentAreaItems, who's actual content is what you want to compare.

Edited, Jul 02, 2014 9:33

To use base classes, you just need to register a UIDescriptor so that the UI knows about this type. We are investigating if we can do this automatically for all base types for content types.

public class YourBaseClassUIDescriptor : UIDescriptor

For interfaces, there is a work around described in the comments section of my blog post:

Jul 02, 2014 12:55

Thanks Linus. I've missed that conversation! Good to know that we can fix it.

Jul 02, 2014 18:09
* 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.