Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Page type "X Page" is not allowed on the root level


Go to End


4 Posts   3100 Views

Avatar
padster

Community Member, 3 Posts

19 July 2014 at 7:12am

I can not for the life of me get a custom admin working, I've followed the docs here:

http://doc.silverstripe.org/framework/en/reference/sitetree

and keep getting the error:

Page type "X Page" is not allowed on the root level

I want my articles administered through the left menu and not appearing as sub pages in the site tree.

Article Holder .php

<?php
class ArticleHolder extends Page {
  private static $allowed_children = array('ArticlePage');
  private static $default_child = 'ArticlePage';
}

<?php
class ArticlePage extends Page {
	private static $db = array(
	'Date' => 'Date',
	'Author' => 'Text'
    );

	private static $allowed_children = 'none';
	private static $can_be_root = false;

	public function getCMSFields() {
	    $fields = parent::getCMSFields();
	     
	    $dateField = new DateField('Date', 'Published Date');
	    $dateField->setConfig('showcalendar', true);
	    $dateField->setConfig('dateformat', 'dd/MM/YYYY');
	             
	    $fields->addFieldToTab('Root.Main', $dateField, 'Content');
	    $fields->addFieldToTab('Root.Main', new TextField('Author', 'Author Name'), 'Content');
	 
	    return $fields;
	}

	public function populateDefaults() {
	    $this->Date = date('Y-m-d');
	    $this->Author = 'Patrick';
	    parent::populateDefaults();
	}

}

class ArticlePage_Controller extends Page_Controller {
}


class ArticleAdmin extends ModelAdmin {
  private static $managed_models = array('ArticlePage'); // Can manage multiple models
  private static $url_segment = 'articles'; // Linked as /admin/products/
  private static $menu_title = 'Articles';
  private static $icon = "cms/images/treeicons/news-file.gif";
}

class Article extends DataObject {
   // ...
   private static $searchable_fields = array(
      'Page Name',
      'Content'
      // leaves out the 'Price' field, removing it from the search
   );
}

Help much appreciated, once cracked I can fly through my other parts.

Avatar
padster

Community Member, 3 Posts

21 July 2014 at 7:16am

Anyone? I've been staring at existing add ons trying to see what I missing here, just to shed more light, using "Simple" theme and sub page of this appears in the menu.

Avatar
camfindlay

Forum Moderator, 267 Posts

21 July 2014 at 2:13pm

If you are getting that "Page type "X Page" is not allowed on the root level" then it is likely to do with the "private static $can_be_root = false;".

On another note, if you want to exclude certain page types from the SiteTree you can use the https://github.com/micschk/silverstripe-excludechildren module.

Hope that helps.

Avatar
padster

Community Member, 3 Posts

22 July 2014 at 12:39am

Hi Cam

Thanks for replying, I'm confused though.

Say you create a "Blog" - when you publish articles to said blog you don't want them to show in the site tree, instead the blog publishing really wants to come from a link on the left menu, click into it and add the page from there.

The problem I have is that when I add a page from there it's showing in the main navigation.

The site I am trying to build is going to be very modular, pages will be very basic to provide content the client will add, but the vast structure is defined by linking to the modules like:

Blog
Events
Galleries
etc