I have a DataObject called ContentSection
that has 2 has_one relationships: to a page type LandingPage
and another DataObject Person
.
class ContentSection extends DataObject {
protected static $has_one = array(
'Person' => 'Person',
'LandingPage' => 'LandingPage'
);
}
Both LandingPage and Person define a has_many relationship to ContentSection.
class LandingPage extends Page {
protected static $has_many = array(
'ContentSections' => 'ContentSection'
);
}
class Person extends DataObject {
protected static $has_many = array(
'ContentSections' => 'ContentSection'
);
}
ContentSections are editable through the LandingPage and Person with the GridFieldConfig_RelationEditor
e.g.:
function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create(10);
$fields->addFieldToTab('Root.Content', new GridField('ContentSections', 'Content Sections', $this->ContentSections(), $config));
return $fields;
}
My question is how can you hide/remove irrelevant has_one fields in the CMS editor tab? The Person and LandingPage relationship dropdown fields both display when you are editing a ContentSection, whether it is for a Person or LandingPage. I only want to show the relevant has_one relationship field. I've tried using dot notation on the has_many relationships:
class Person extends DataObject {
protected static $has_many = array(
'ContentSections' => 'ContentSection.Person'
);
}
I've also tried using the removeFieldFromTab
method in the getCMSFields
method of the ContentSection
class, where I define the other CMS fields for the ContentSection:
$fields->removeFieldFromTab('Root.Main', 'Person');