burnbright/silverstripe-hasonefield

使用 GridField 编辑 has_one 关系,通过点击按钮触发。

安装次数: 38,371

依赖项: 5

建议者: 0

安全性: 0

星标: 34

关注者: 7

分支: 30

开放性问题: 3

类型:silverstripe-vendormodule

4.0.1 2023-08-30 04:02 UTC

README

Build Status Latest Stable Version Latest Unstable Version

允许您创建一个 CMS 按钮来创建和编辑单个相关对象。它实际上是一个网格字段,但看起来像一个按钮。

demo

安装

composer require silvershop/silverstripe-hasonefield

用法

    use SilverShop\HasOneField\HasOneButtonField;

    private static $has_one = [
        'Address' => 'Address'
    ];

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab("Root.Main",
            HasOneButtonField::create($this, "Address")
        );

        return $fields;
    }

您必须通过父上下文($this)传递,以便可以通过 GridFieldDetailForm 设置 has_one 关系。

过滤结果

要过滤选择器中显示的结果,请使用 HasOneAddExistingAutoCompleter::setSearchList

$property = HasOneButtonField::create(
    $this,
    'Address'
);

$property
    ->getConfig()
    ->getComponentByType(HasOneAddExistingAutoCompleter::class)
    ->setSearchList(Property::get()->filter("Country", "GB"));

$fields->addFieldToTab(
    'Root.Main',
    $property
);