Hello,
I have "Class" and "Student" as two dataobjects that are managed in ModelAdmins. When I click to edit a Class record, two tabs show "Main", and "Students". I can edit Class details in the Main tab, and a list of students that belong to the class show in Students tab. I'm using the following code:
public function getCMSFields() {
// return new FieldList(
// new TextField('Title', 'Class Name'),
// new ReadonlyField('RegisteredStudents', 'Registered Students'),
// new DropdownField('MemberID', 'School Admin', DataList::create("Member")->map("ID", "Title"))
// );
// Get the fields from the parent implementation
$fields = parent::getCMSFields();
// Create a default configuration for the new GridField, allowing record editing
$config = GridFieldConfig_RelationEditor::create();
// Set the names and data for our gridfield columns
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'FirstName' => 'FirstName',
'Surname' => 'Surname',
'Course.Title'=> 'Course' // Retrieve from a has-one relationship
));
// Create a gridfield to hold the student relationship
$studentsField = new GridField(
'Students', // Field name
'Student', // Field title
$this->Students(), // List of all related students
$config
);
$fields->addFieldToTab('Root.Students', $studentsField);
return $fields;
}
The problem with this is when I uncomment the FieldList at the top of the code so I can override "Class" dataobject fields, the students tab disappears.
any help what's wrong with the code above?
thanks