PHP code example of hchokshi / silverstripe-hasonefield
1. Go to this page and download the library: Download hchokshi/silverstripe-hasonefield library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hchokshi / silverstripe-hasonefield example snippets
use SilverShop\HasOneField\HasOneButtonField;
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",
// $dataObject, 'RelationName', 'Optional title - would default to Relation Name'
HasOneButtonField::create($this, "Address") //here!
);
return $fields;
}