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.
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;
}
You must pass through the parent context ($this), so that the has_one
relationship can be set by the GridFieldDetailForm
.