I have a nested Dataobjects to create Accordion and Accordion Tabs
I created a Accordion first and saved it and is working fine.
Now I add a new Accordion Tab to the Accordion it save without the AccordionPageID.
Accordion Page
class AccordionPage extends Page
{
private static $has_many = array(
"Accordions" => "Accordion",
"AccordionTabs" => "AccordionTab",
);
private static $has_one = array(
'RootFolder' => 'Folder'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
//$fields->removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root', $accordion = new Tab('Accordions'));
$accordion->setTitle(_t('AccordionPage.ACCORDION', 'Accodrions'));
if ($rootFolder = $this->RootFolder()) {
$accordionConfig = GridFieldConfig_RecordEditor::create();
if(class_exists('GridFieldBulkManager')) {
$accordionConfig->addComponent(new GridFieldBulkManager());
}
if(class_exists('GridFieldSortableRows')) {
$accordionConfig->addComponent(new GridFieldSortableRows('SortOrder'));
}
$accordionField = new GridField('Accordions', 'Accordions', $this->Accordions(), $accordionConfig);
$fields->addFieldToTab("Root.Accordions", $accordionField);
} else {
$fields->addFieldToTab(
"Root.Accordions",
new HeaderField(
_t("AccordionPage.ACCORDIONNOTSAVED", "You may add accordions once you have saved the page for the first time."),
$headingLevel = "3"
)
);
}
return $fields;
}
}
Accordion DataObject
class Accordion extends DataObject
{
private static $has_one = array(
'AccordionPage' => 'AccordionPage',
'AccordionFolder' => 'Folder'
);
private static $has_many = array(
"AccordionTabs" => "AccordionTab",
);
function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
$fields->addFieldsToTab('Root.Main', array(
new TextField('Name', _t('AccordionPage.ACCORDIONNAME','Accordion Name'), null, 255),
new TextareaField('Description', _t('AccordionPage.DESCRIPTION','Description'))
));
if ($accordionFolder = $this->AccordionFolder()) {
$accordionConfig = GridFieldConfig_RecordEditor::create();
if(class_exists('GridFieldBulkManager')) {
$accordionConfig->addComponent(new GridFieldBulkManager());
}
if(class_exists('GridFieldSortableRows')) {
$accordionConfig->addComponent(new GridFieldSortableRows('SortOrder'));
}
$accordionField = new GridField('AccordionTabs', 'Tabs', $this->AccordionTabs(), $accordionConfig);
$fields->addFieldToTab("Root.AccordionTabs", $accordionField);
} else {
$fields->addFieldToTab(
"Root.AccordionTabs",
new HeaderField(
_t("AccordionPage.ACCORDIONTABNOTSAVED", "You may add tabs once you have saved the page for the first time."),
$headingLevel = "3"
)
);
}
return $fields;
}
AccordionTab DataObject
class AccordionTab extends DataObject
{
private static $db = array(
'TabName' => 'Varchar(255)',
'Description' => 'Text',
'SortOrder' => 'Int',
'URLSegment' => 'Varchar(255)',
'showContent' => 'Boolean',
'TabContent' => 'HTMLText'
);
private static $has_one = array(
'AccordionPage' => 'AccordionPage',
'Accordion' => 'Accordion',
'Folder' => 'Folder'
);
static $summary_fields = array(
'TabName' => 'Title',
'Description' => 'Description'
);
function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
$fields->addFieldsToTab('Root.Main', array(
new TextField('TabName', _t('AccordionPage.TABNAME','Tab Title'), null, 255),
new TextareaField('Description', _t('AccordionPage.DESCRIPTION','Description'))
));
return $fields;
}
When I Add accordion Tab it does not save AccordionPage ID . it only saves the AccordionID.