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.

Customising the CMS /

getCMSFields problem


Reply


3 Posts   1110 Views

Avatar
Mediaversa

Community Member, 5 Posts

4 June 2010 at 1:34am

Hello everyone,

I'm working on a website with silverstripe, and I'm running into a problem. I'm trying to add a new tab with 2 fields on multiple pagetypes (like 20), and on 6 of them, the fields are not added after flushing. The stupid thing is that the pages are 99% equal to eachother, except for the fieldnames.

It there something that can prevent silverstripe from adding the fields to the cms when flushing?

The code I've used:

class HistoriePage extends SiteTree
{
   static $db = array(
   'BlauwKopHistorie' => 'Varchar(100)',
   'BlauwContentHistorie' => 'Varchar(255)',
   );
   
   function getCMSFields()
   {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab("Root.Content.BlauwVeld", new TextField('BlauwKopHistorie', 'Koptekst'));
      $fields->addFieldToTab("Root.Content.BlauwVeld", new TextField('BlauwContentHistorie', 'Inhoud'));
      return $fields;
   }
   
   public static $has_one = array(
   );
}

class HistoriePage_Controller extends ContentController
{   
   public function init() {
      parent::init();

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work
      // Requirements::themedCSS("layout");
      // Requirements::themedCSS("typography");
      // Requirements::themedCSS("form");
      i18n::set_locale('nl_NL');
   }
}

Thanks in advance,
Xander

Avatar
Willr

Forum Moderator, 5513 Posts

4 June 2010 at 12:06pm

As an aside, is there any reason why you are extending SiteTree rather than extending your base class 'Page.php'. On the 6 pages which aren't showing the fields are they of the correct page type 'HistoriePage'. What does the dropdown say on the Behaviour tab on one of those 6 pages.

Avatar
Mediaversa

Community Member, 5 Posts

4 June 2010 at 7:40pm

The reason I expended it on SiteTree rather then Page, is because I've used "Page" as my homepage, and added some fields to to that one which are only needed on the homepage.

The point is, it's not 1 pagetype I'm using. The website I'm working on, does have different templates all over the page, which makes me need to create different templates for every page. I need to add these 2 fields mentioned before on every of these pages. I've done that by creating the fields on one of the pagetypes, testing it, and then duplicated them to all the other pagetypes. Ofcourse I've changed the fieldnames in every template, As I know that duplicated fields are not allowed. It worked out for most of the templates, but 6 of them don't. The most annoying thing is that if I compare the .php files of the pagetypes with eachother, only the fieldnames are different. I have no clue why the rest won't work:/. When using the dev/build option, the fields are just not getting added. Nothing happens at all, however when I add more fields on one of the pages that does work, they are added without any problems....