Hi there,
I'm trying to customise tutorial 5 by being able to add images, links and dates to the modules.
The problem is when I open the popup the image uploader says "Images can be attached once you have saved the record for the first time." so I have to fill in the other data click save and then reopen/edit it to be able to upload an image.
Also I'm using $many_many but I'd like to only be able to select a maximum of 7 modules instead of unlimited. Is this possible?
My developer skills are not great so any help is much appreciated :)
Module.php
<?php
class Module extends DataObject {
static $db = array(
'CompanyName' => 'Text',
'StartDate' => 'Date'
);
static $has_one = array(
'Logo' => 'Image',
'PremiumLink' => 'SiteTree'
);
static $belongs_many_many = array(
'Projects' => 'Project'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'CompanyName', 'Company Name' ) );
$fields->push( $startdateField = new DateField( 'StartDate', 'Start Date' ) );
$startdateField->setConfig('showcalendar', true);
$startdateField->setConfig('DD MM YYYY');
$fields->push( new TreeDropdownField( 'PremiumLinkID', 'Link to page', 'SiteTree')); //Note the ID added after the fieldname
$fields->push( new ImageField( 'Logo' ) );
return $fields;
}
}
?>
Project.php
<?php
class Project extends Page {
static $has_one = array(
);
static $many_many = array(
'Modules' => 'Module'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$modulesTablefield = new ManyManyComplexTableField(
$this,
'Modules',
'Module',
array(
'CompanyName' => 'Company Name',
'StartDate' => 'Start Date',
'PremiumLinkID' => 'Premium Link',
'Logo' => 'Company Logo'
),
'getCMSFields_forPopup'
);
$modulesTablefield->setAddTitle( 'A Module' );
$fields->addFieldToTab( 'Root.Content.Modules', $modulesTablefield );
return $fields;
}
}
class Project_Controller extends Page_Controller {
}
?>