Well, as it turns out, a many many complex table field is perhaps not what I actually wanted.
The unit list with the many many relationship is the same per for all the properties, whereas I wanted to be able to make a unit list per property..
I did try to swap out the many_many portions of my code for has_many but that didn't actually work as I expected.
Is there a particular route I should be taking to get this to work?
PropertyPage.php
static $has_many = array(
'AvailableUnits' => 'UnitList'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$Unitstablefield = new HasManyComplexTableField(
$this,
'AvailableUnits',
'UnitList',
array(
'UnitNumber' => 'UnitNumber',
'UnitType' => 'Unit Type',
'UnitArea' => 'Unit Area',
'UnitRent' => 'Unit Rent',
'UnitLet' => 'Unit Let'
),
'getCMSFields_forPopup'
);
$Unitstablefield->setAddTitle( 'A Unit' );
$Unitstablefield->setPageSize(100);
$fields->addFieldToTab( 'Root.Content.Units', $Unitstablefield );
UnitList.php
<?php
class UnitList extends DataObject {
static $db = array(
'UnitNumber' => 'Text',
'UnitType' => 'Text',
'UnitArea' => 'Text',
'UnitRent' => 'Text',
'UnitLet' => 'Boolean'
);
static $has_one = array(
'UnitSpec' => 'File',
'UnitLease' => 'File'
);
static $belongs_has_many = array(
'PropertyPages' => 'PropertyPage'
);
function getCMSFields_forPopup() {
return new FieldSet(
new TextField( 'UnitNumber', 'UnitNumber' ),
new TextField( 'UnitType', 'Unit Type' ),
new TextField( 'UnitArea', 'Unit Area' ),
new TextField( 'UnitRent', 'Unit Rent' ),
new CheckboxField ('UnitLet', 'Tick if Let' ),
new FileIFrameField( 'UnitSpec', 'Unit Specsheet' ),
new FileIFrameField( 'UnitLease', 'Unit Lease Document' )
);
}
}
?>
Any ideas?
Kevin.