Skip to content

Edit a has_one relationship using the gridfield editor, triggered by clicking a button.

Notifications You must be signed in to change notification settings

lpostiglione/silverstripe-hasonefield

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SilverStripe has_one field

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

Usage

In Warehouse.php context:

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		if($this->Address()->exists()){
			$fields->addFieldsToTab("Root.Main", array(
				ReadonlyField::create("add", "Address", $this->Address()->toString())
			));
		}
		$fields->removeByName("AddressID");
		$fields->addFieldToTab("Root.Main",
			HasOneButtonField::create("Address", "Address", $this) //here!
		);

		return $fields;
	}

You must pass through the parent context ($this), so that the has_one relationship can be set by the GridFieldDetailForm.

Caveats

The field name must match the has_one relationship name.

About

Edit a has_one relationship using the gridfield editor, triggered by clicking a button.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%