Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Issues Customising Tutorial 5


Go to End
Reply


4 Posts   899 Views

Avatar
ambient

Community Member, 128 Posts

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 {
	
}

?>

Avatar
ambient

Community Member, 128 Posts

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 :)

Avatar
Devlin

Community Member, 237 Posts

2 July 2011 at 4:08am

Edited: 02/07/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
	}
}

Avatar
ambient

Community Member, 128 Posts

2 July 2011 at 7:58am

Awesome, Thanks Devlin :D