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

Vote:
 

I have a property with an allowed type restriction:

[Display(
    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.

#86968
Jun 05, 2014 12:11
Vote:
 

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.

#86970
Jun 05, 2014 12:17
Vote:
 

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.

/T

#88099
Edited, Jul 01, 2014 20:42
Vote:
 

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

#88104
Jul 02, 2014 0:38
Vote:
 

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.

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=77678

**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.

#88108
Edited, Jul 02, 2014 9:33
Vote:
 

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.

[UIDescriptorRegistration]
public class YourBaseClassUIDescriptor : UIDescriptor
{
}

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

http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/Restriction-of-content-types-in-properties/

#88123
Jul 02, 2014 12:55
Vote:
 

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

#88141
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.