Usage
*
*
* $tablefield = new HasOneComplexTableField(
* $this,
* 'MyOnlyFruit',
* 'Fruit',
* array(
* 'Name' => 'Name',
* 'Color' => 'Color'
* ),
* 'getCMSFields_forPopup'
* );
*
*
* **Notice** : You still have different ways to customize the popup window as in the parent-class [ComplexTableField](ComplexTableField).
*
* This field is made to manage a **has_one** relation. In the SilverStripe relation between DataObjects, you can use this relation for **1-to-1** and **1-to-many** relations.
* By default, a HasOneComplexTableField manages a **1-to-many** relation. If you want to specify that the relation that you manage is a **1-to-1** relation, add this code :
*
*
* $tablefield->setOneToOne();
*
*
* @package forms
* @subpackage fields-relational
*/
class HasOneComplexTableField extends HasManyComplexTableField {
public $itemClass = 'HasOneComplexTableField_Item';
public $isOneToOne = false;
public function getParentIdName($parentClass, $childClass) {
return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one');
}
public function getControllerJoinID() {
return $this->controller->{$this->joinField};
}
public function saveInto(DataObjectInterface $record) {
$fieldName = $this->name;
$fieldNameID = $fieldName . 'ID';
$record->$fieldNameID = 0;
if($val = $this->value[ $this->htmlListField ]) {
if($val != 'undefined')
$record->$fieldNameID = $val;
}
$record->write();
}
public function setOneToOne() {
$this->isOneToOne = true;
}
public function isChildSet($childID) {
return DataObject::get($this->controllerClass(), '"' . $this->joinField . "\" = '$childID'");
}
public function ExtraData() {
$val = $this->getControllerJoinID() ? $this->getControllerJoinID() : '';
$inputId = $this->id() . '_' . $this->htmlListEndName;
return <<