silvershop/silverstripe-hasonefield

Edit a has_one relationship using a GridField, triggered by clicking a button.

Installs: 14 181

Dependents: 9

Suggesters: 0

Stars: 23

Watchers: 6

Forks: 17

Open Issues: 3

Type:silverstripe-vendormodule

3.0.0 2018-11-07 20:45 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.

demo

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.