I'm trying to get a "featured content" thing happening.
There's supposed to be a bit of text, a heading, an associated image and two page id's.
One would be for the page where the content will be displayed and the other would be a page that the user would be taken to if they click on the associated image.
I've read that the TreeDropdownField doesn't work in widgets, so I've created a page where users can input the featured content and say on which pages they want it.
So far it looks like this:
class FeaturedContent extends DataObject{
static $db = array(
"FeaturedContentTitle" => "Varchar(40)",
"FeaturedContentText" => "Text",
"FeaturedContentDisplay" => "Boolean"
);
static $has_one = array(
"FeaturedContentHostPage" => "SiteTree",
"FeaturedContentLink" => "SiteTree",
"FeaturedContentImage" => "Image"
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField("FeaturedContentTitle", "Title"));
$fields->push(new TextareaField("FeaturedContentText", "Text"));
$fields->push(new CheckboxField("FeaturedContentDisplay", "Display this content?"));
$fields->push(new TreeDropdownField("FeaturedContentHostPageID", "Display On", 'SiteTree'));
$fields->push(new TreeDropdownField("FeaturedContentLinkID", 'Linkto', 'SiteTree'));
$fields->push(new ImageField("FeaturedContentImage", "Associated Image"));
return $fields;
}
}
class ManageFeaturedContentPage extends Page{
function getCMSFields() {
$fields = parent::getCMSFields();
$FeaturedContent = Object::create("FeaturedContent");
$TableField = new ComplexTableField(
$controller = $this,
$name = "lstFeaturedContent",
$sourceClass = $FeaturedContent->class,
$fieldList = array(
'FeaturedContentTitle' => 'Content Title',
'FeaturedContentText' => 'Content'
),
$functionForPopupFields = "getCMSFields_forPopup",
$sourceFilter = "",
$sourceSort = "FeaturedContentTitle"
);
$TableField->setPermissions(
array(
"add",
"edit",
"delete"
)
);
$fields->addFieldToTab( 'Root.Content.Main', $TableField );
$fields->removeFieldFromTab('Root.Content.Main', 'Content');
return $fields;
}
}
Now, the odd bit is that the image works fine and ONE of the TreeDropdownFields works fine, but it only ever displays one. I can never get them both displayed and working. Sometimes it's one, sometimes it's the other (can't figure out the rule behind this) and whatever column is not displayed automatically gets assigned the page id of the manage featured content page.
I've tried using different browsers and tried it on versions 2.3.4 and 2.3.2 and it doesn't work on either of them.
Can anyone tell me what I am doing wrong?