EDIT: cleaned up the code for easier reading.
I'm trying to make a set of pages that contain multiple slideshows.
It's supposed to look basically like this...Images have a many to one relationship with a slideshow and a slideshow has a many to many relationship across several pages/types.
I've set up a templateless class to house my slideshows, but I'm missing how exactly to access these slideshows and display them on their related template. It would seem I have the relationships correct as I can create a slideshow in teh holder and from the pages that I want the slideshow to appear on, I can select that slideshow in the cms. See screenshots. I'm just not sure how to display them.
Thanks a ton, to anyone that can take a look at this!
Here is the code for the Images and Slideshow:
/mysite/code/SlideImage.php
class SlideImage extends DataObject {
static $db = array(
'Label' => 'Text',
'SlideOrder' => 'Text'
);
static $has_one = array('Image' => 'Image');
static $belongs_many_many = array('SlideshowBuckets' => 'SlideshowBucket');
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField('Label'));
$fields->push( new TextField('SlideOrder'));
$fields->push( new ImageField('Image'));
return $fields;
}
}
/mysite/code/SlideshowBucket.php
class SlideshowBucket extends Page {
static $allowed_children = array();
static $db = array(
'Headline' => 'Text',
'Copy' => 'Text',
'Link' => 'Text'
);
static $many_many = array('SlideImages' => 'SlideImage');
static $belongs_many_many = array(
'WorkContentDetailPages' => 'WorkContentDetailPage',
'WorkHomePages' => 'WorkHomePage'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'));
$fields->addFieldToTab('Root.Content.Main', new TextareaField('Copy'));
$fields->addFieldToTab('Root.Content.Main', new TextField('Link'));
$fields->removeFieldFromTab('Root.Content.Main','Content');
$modulesTablefield = new ManyManyComplexTableField(
$this,
'SlideImages',
'SlideImage',
array(
'Label' => 'Image Label',
'SlideOrder' => 'Image Order',
'Image' => 'Image Preview'
),
'getCMSFields_forPopup'
);
$modulesTablefield->setAddTitle( 'An Image' );
$fields->addFieldToTab('Root.Content.SlideImage',$modulesTablefield);
return $fields;
}
}
And finally, this is the pages that I want my slideshows to appear on:
/mysite/code/WorkContentDetailPage
class WorkContentDetailPage extends Page {
static $allowed_children = array('SlideshowBucket');
static $many_many = array('SlideshowBuckets' => 'SlideshowBucket');
function getCMSFields() {
$fields = parent::getCMSFields();
$modulesTablefield = new ManyManyComplexTableField(
$this,
'SlideshowBuckets',
'SlideshowBucket',
array(
'Title' => 'Title',
'Headline' => 'Headline'
),
'getCMSFields_forPopup'
);
$modulesTablefield->setAddTitle( 'A Slideshow Module' );
$fields->addFieldToTab('Root.Content.SlideshowBucket',$modulesTablefield);
return $fields;
}
}
class WorkContentDetailPage_Controller extends Page_Controller {}