silvershop/silverstripe-hasonefield

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

安装数: 351,889

依赖者: 28

建议者: 1

安全: 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
);