I have a 2 part question. I've got a ListboxField that I've added to my getCMSFields() function but doesn't show up on the page. I confirmed that it's getting the correct data and is actually creating a ListboxField object, but that field just never appears in the CMS. Another ListboxField built the same way shows up fine.
Related to that somewhat, both of the belongs_many_many relations I am using to populate those listbox fields also have their own tab branching off of root.main. However, I never wrote anything that should have built them and they display nothing, how do I get rid of them?
The relevant code is as follows:
class EducationPost extends DataObject{
private static $db = array(
'Title' => 'Text',
'Slug' => 'Text',
'Teaser' => 'Text',
'OnFrontPage' => 'Boolean',
'Published' => 'Boolean'
);
private static $belongs_many_many = array(
'Topics' => 'Topic',
'Resources' => 'Resource'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
Requirements::javascript('mysite/code/title-to-slug.js');
$fields->addFieldsToTab('Root.Main', array(
TextField::create('Title', 'Page Title'),
TextField::create('Slug', 'URL Segment'),
TextareaField::create('Teaser', 'Teaser description (200 Characters)'),
CheckboxField::create('OnFrontPage', 'Show on Front Page?'),
CheckboxField::create('Published', 'Published?')
));
$source = Topic::get()->map('ID', 'Title')->toArray();
$value = array_keys($this->Topics()->getIDList());
$fields->addFieldToTab('Root.Main',
ListboxField::create('Topics', 'Topic', $source, $value, $size = null, $multiple = true)
);
$source = Resource::get()->map('ID', 'Title')->toArray();
$value = array_keys($this->Resources()->getIDList());
$fields->addFieldToTab('Root.Main',
ListboxField::create('Resources', 'Resource', $source, $value, $size = null, $multiple = true)
, 'Topic');
return $fields;
}
}
class Resource extends DataObject {
//class Topic is built the same way
private static $db = array(
'Title' => 'Varchar',
'Teaser' => 'Text'
);
private static $many_many = array(
'EducationPosts' => 'EducationPost'
);
public function requireDefaultRecords() {
parent::requireDefaultRecords();
$topics = Topic::get();
if (!$topics->exists()) {
$topic = new Topic();
$topic->Title = 'foo';
$topic->write();
}
}
}