Page type restriction to root page

Vote:
 

Hi,

   I need to apply page type restriction to root page structure.My cms site page root structure look like this:

     - Root

        -The Table

          -Home

             -Page 1

                -Page 2

                   -Page 3

I want to restrict Page 1,page 2 with same page type and page 3 with another page type.Is it possible to implement in cms.

Thanks

#148235
May 06, 2016 16:41
Vote:
 

You can restrict what page types are allowed to be created as children. Decorate your content type with 

http://world.episerver.com/documentation/Class-library/?documentId=cms/9/145DE4A6

An example for root page 

[ContentType(GUID = "3415B788-8359-4BF0-9375-2FE9BA90719B",
             AvailableInEditMode = false)]
[AvailableContentTypes(Include = new[] {
                                        typeof(StartPage),
                                        typeof(ContainerPage))]
public class SysRoot : PageData
{
}
#148239
Edited, May 06, 2016 17:02
Vote:
 

Thanks for your help

Dileep

#149226
May 26, 2016 15:44
Vote:
 

This approach is not working in the current CMS version 11.

Does anybody knows how to accomplish this in version 11?

#204961
Jun 24, 2019 13:01
Vote:
 
[ContentType(
        GUID = "19671657-B684-4D95-A61F-8DD4FE60D559",
        GroupName = Global.GroupNames.Specialized)]
    [SiteImageUrl]
    [AvailableContentTypes(
        Availability.Specific,
        Include = new[] { typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(ISearchPage), typeof(LandingPage), typeof(ContentFolder) }, // Pages we can create under the start page...
        ExcludeOn = new[] { typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(ISearchPage), typeof(LandingPage) })] // ...and underneath those we can't create additional start pages
public class StartPage : SitePageData
{
//properties...
}

It's pretty similar. You get some options on the Availability flag to choose between including All, None or Specific. Choose specific and then set the Include to all pages types you want should be available under this page type. If you want to exclude this page type below some other page types, you can use the ExcludeOn property. Normally I only use the Include option...

#204963
Jun 24, 2019 13:33
Vote:
 

Thanks for the reply, but that is restriction for the StartPage. I want to add a restriction to the Root page like is it show in the post above.

   I.e. Under the site's Root to be able to add only the StartPage and SettingsPage type. 

#204967
Jun 24, 2019 13:51
Vote:
 
#204970
Jun 24, 2019 14:03
Vote:
 

I saw that blog post too and that I used in my example and it's not working in CMS 11.

Thank you again for your assistance.

#204980
Jun 24, 2019 18:23
Vote:
 

Hi Nenad,

The only way I believe you can do this for the Root is via the IAvailableSettingsRepository.

I've had success with the following previously:

[InitializableModule]
[ModuleDependency(typeof(CmsCoreInitialization))]
public class RestrictRootPagesInitialization : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var contentTypeRepository = context.Locate.Advanced.GetInstance<IContentTypeRepository>();

        var sysRoot = contentTypeRepository.Load("SysRoot") as PageType;

        var setting = new AvailableSetting { Availability = Availability.Specific };
        setting.AllowedContentTypeNames.Add(contentTypeRepository.Load<StartPage>().Name);
        setting.AllowedContentTypeNames.Add(contentTypeRepository.Load<ContainerPage>().Name);

        var availableSettingsRepository = context.Locate.Advanced.GetInstance<IAvailableSettingsRepository>();
        availableSettingsRepository.RegisterSetting(sysRoot, setting);
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}
#204981
Edited, Jun 24, 2019 18:52
Vote:
 

Hi Jake, 

This works perfectly! Thanks a lot!!

#204995
Jun 25, 2019 10:06
Vote:
 

Nice! I hadn't seen the IAvailableSettingsRepository interface before. That's good to know.

#204996
Jun 25, 2019 10:11
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.