21286 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 687 Views |
-
Issues Customising Tutorial 5

29 June 2011 at 5:34am
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 {
}?>
-
Re: Issues Customising Tutorial 5

1 July 2011 at 10:24pm
Nobodies got any ideas on this? I kind of thought it would be an easy solution, just something I did wrong to cause the image uploader to behave like that?
Any ideas? Pleeeeeeeeease
-
Re: Issues Customising Tutorial 5

2 July 2011 at 4:08am Last edited: 2 July 2011 6:52am
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?
$modules = $this->Modules();
if( !empty($modules) ) {
$count = $modules->Count();
if( !empty($count) && $count>=8 ) {
// do something
}
}
| 687 Views | ||
|
Page:
1
|
Go to Top |


