我有一個數據對象稱爲ContentSection
有2個has_one關係:對一個頁面類型LandingPage
和另一個數據對象Person
。Silverstripe刪除不相關的has_one關係字段在CMS選項卡
class ContentSection extends DataObject {
protected static $has_one = array(
'Person' => 'Person',
'LandingPage' => 'LandingPage'
);
}
LandingPage和Person都定義了與ContentSection的has_many關係。
class LandingPage extends Page {
protected static $has_many = array(
'ContentSections' => 'ContentSection'
);
}
class Person extends DataObject {
protected static $has_many = array(
'ContentSections' => 'ContentSection'
);
}
ContentSections通過的LandingPage和人與GridFieldConfig_RelationEditor
例如爲:可編輯
function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create(10);
$fields->addFieldToTab('Root.Content', new GridField('ContentSections', 'Content Sections', $this->ContentSections(), $config));
return $fields;
}
我的問題是你怎麼能隱藏/刪除無關HAS_ONE領域的CMS編輯器選項卡?在編輯ContentSection時,無論是Person還是LandingPage,都會顯示Person和LandingPage關係下拉字段。我只想顯示相關的has_one關係字段。我已經使用上的has_many關係點符號的嘗試:
class Person extends DataObject {
protected static $has_many = array(
'ContentSections' => 'ContentSection.Person'
);
}
我已經使用在ContentSection
類,在這裏我定義其他CMS領域的ContentSection的getCMSFields
方法removeFieldFromTab
方法也試過:
$fields->removeFieldFromTab('Root.Main', 'Person');