burnbright / silverstripe-hasonefield
使用 GridField 编辑 has_one 关系,通过点击按钮触发。
4.0.1
2023-08-30 04:02 UTC
Requires
- silverstripe/framework: ^4.0 || ^5.0
- silverstripe/vendor-plugin: ^1.0 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^5.7
Replaces
This package is auto-updated.
Last update: 2024-09-04 18:14:25 UTC
README
允许您创建一个 CMS 按钮来创建和编辑单个相关对象。它实际上是一个网格字段,但看起来像一个按钮。
安装
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 );