小编bre*_*own的帖子

Silverstripe删除CMS选项卡中不相关的has_one关系字段

我有一个被调用的DataObject ContentSection,它有2个has_one关系:到页面类型LandingPage和另一个DataObject Person.

class ContentSection extends DataObject {
    protected static $has_one = array(
        'Person'        => 'Person',
        'LandingPage'   => 'LandingPage'
    );
}
Run Code Online (Sandbox Code Playgroud)

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'
    );
}
Run Code Online (Sandbox Code Playgroud)

ContentSections可以通过LandingPage和Person编辑,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;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何在CMS编辑器选项卡中隐藏/删除不相关的has_one字段 …

silverstripe

2
推荐指数
1
解决办法
875
查看次数

标签 统计

silverstripe ×1