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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[SOLVED] Show SiteTree inside getCMSFields_forPopup()


Reply

1047 Views

Avatar
Mrfixer

4 July 2011 at 9:59am (Last edited: 4 July 2011 10:10pm), Community Member, 49 Posts

Hi im trying to get the sitetree to show inside the dataobjectmanager popup, heres what im hoping to achieve

1) upload a set of images
2) apply captions and titles to each
3) add an internal link that echos out on page inside a span. (like a "read more")

1) and 2) are no problem, working great, applying the sitetree however is giving me grief, this is what i have..

My Class file:

<?php
class HomepageImageResource extends DataObject
{
static $db = array (
'HomepageTitle' => 'Text',
'HomepageCaption' => 'Text'
);

static $has_one = array (
'HomepageAttachment' => 'Image',
'HomepageInternalLink' => "SiteTree"
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('HomepageTitle'),
new TextareaField('HomepageCaption'),
new FileIFrameField('HomepageAttachment')
// new SimpleTreeDropdownField( 'HomepageInternalLinkID', 'HomepageInternalLink', 'SiteTree' )
);
}
}

now onto my HomePage extends Page: (note the "// this causes me the error" comment) without that line all works ok but no sitetree

class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);

static $has_many = array (
'HomepageImages' => 'HomePageImageResource'
);

function getCMSFields() {

$fields = parent::getCMSFields();

$fields->removeFieldFromTab('Root.Content.Main', 'Content');

$fields = parent::getCMSFields();
$homepagemanager = new ImageDataObjectManager(
$this, // Controller
'HomepageImages',
'HomepageImageResource',
'HomepageAttachment',
'HomepageInternalLink', // this causes me the error"

array(
'HomepageTitle' => 'HomepageTitle',
'HomepageCaption' => 'HomepageCaption'
), // Headings
'getCMSFields_forPopup'
);
$fields->addFieldToTab("Root.Content.Main",$homepagemanager);

$fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent');

return $fields;
}

}

UPDATE: Marked as Solved
this is what i needed to do to get it working if anyone else comes across this issue:

In HomePage.php i changed the getCMSFields() function to:

function getCMSFields() {

$fields = parent::getCMSFields();

$fields->removeFieldFromTab('Root.Content.Main', 'Content');

$fields = parent::getCMSFields();
$homepagemanager = new ImageDataObjectManager(
$this, // Controller
'HomepageImages', // Source name
'HomepageImageResource', // Source class
'HomepageAttachment', // File name on DataObject
//'HomepageInternalLink',

array(
'HomepageTitle' => 'HomepageTitle',
'HomepageCaption' => 'HomepageCaption'
),
'getCMSFields_forPopup'
);

$homepagemanager->setRelationAutoSetting(false);

$fields->addFieldToTab("Root.Content.Main",$homepagemanager);

$fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent');

return $fields;
}

overriding default setRelationAutoSetting to false