silvershop/silverstripe-hasonefield
Edit a has_one relationship using a GridField, triggered by clicking a button.
Maintainers
Package info
github.com/silvershop/silverstripe-hasonefield
Type:silverstripe-vendormodule
pkg:composer/silvershop/silverstripe-hasonefield
Requires
- php: ^8.3
- silverstripe/framework: ^6
- silverstripe/vendor-plugin: ^3
Requires (Dev)
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
BSD-2-Clause 608b4aa7dcf1d94ecf1a01c3a47f47d5ce55029d
This package is auto-updated.
Last update: 2026-06-11 03:53:11 UTC
README
👁 Build Status
👁 Latest Stable Version
👁 Latest Unstable Version
Allows you to create a CMS button for creating and editing a single related object. It is actually a grid field, but just looks like a button.
Installation
composer require silvershop/silverstripe-hasonefield
Usage
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; }
You must pass through the parent context ($this), so that the has_one
relationship can be set by the GridFieldDetailForm.
Filtering Results
To filter the results shown in the picker use HasOneAddExistingAutoCompleter::setSearchList.
$property = HasOneButtonField::create( $this, 'Address' ); $property ->getConfig() ->getComponentByType(HasOneAddExistingAutoCompleter::class) ->setSearchList(Property::get()->filter("Country", "GB")); $fields->addFieldToTab( 'Root.Main', $property );
