Allow child page type only under parent page type

Vote:
 

I'm trying to create a page type and a container for pages of that type named OwnerStoryPage and OwnerStoryContainer respectively. Using the AvailableContentTypesAttribute, I've resticted the OwnerStoryContainer to only allow OwnerStoryPages beneath it. What I want to do now is only allow an OwnerStoryPages to be created under an OwnerStoryContainer. I don't want OnwerStoryPage type to show as an option when creating a new page under any other page types. Because Exclude and ExcludeOn seem to always override Include and IncludeOn, I can't seem to find a way to do this. How can I exclude OwnerStoryPage on all types but OwnerStoryContainer?

    [ContentType(DisplayName = "Owner Stories Container", ...)]
    [AvailableContentTypes(Include = new Type[] { typeof(OwnerStoryPage) })]
    public class OwnerStoriesContainer : GenericContainerPage
    {
         ...
    }
[ContentType(DisplayName = "Owner Stories Container", ...)]
    [AvailableContentTypes(?)]
    public class OwnerStoriesContainer : GenericContainerPage
    {

    }
#144937
Feb 22, 2016 22:42
Vote:
 

If you only want the OwnerStoriesContainer to be able to have OwnerStoryPage I think it's easiest to set this on the OwnerStoryPage and ExcludeOn with all other page types

#144942
Feb 22, 2016 23:38
Vote:
 

Thanks Alf. I guess I should have elaborated that the problem I have with that is it's a maintenance problem. When new Page Types are added, developers won't know or remember to go update that exclusion list. If that tactic is used frequently, going through multiple files to update multiple exclusion lists is not really going to be worth the effort either. I don't want any coupling between these two page types and any other page types on the site. I tried ExcludeOn the base page type, but that took precidence over the include so that OwnerStoryPage wasn't available on OwnerStoriesContainer. There seems to be a missing "IncludeOnlyOn" or "ExcludeOnNot" option.

#144999
Feb 23, 2016 16:26
Vote:
 

If you don't want any coupling then using only Include everywhere is an option. Will be a little more typing though for page types with many allowed page types :)

#145004
Feb 23, 2016 17:04
Vote:
 

I have an idea for this scenario.

What if you create an interface, ISpecialized, that you exclude in all AvailableContentTypes attributes. You add this "marker interface" to all your specialized-use content types, and they will be removed from all Add dialogs by default.

Then you will only see them if you include them specifically in a certain parent content type.

#174217
Jan 21, 2017 12:05