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.

Customising the CMS /

[polls] SS 2.4 PollChoices DataObjectDecorator


Reply


384 Views

Avatar
Imploosio

Community Member, 5 Posts

27 September 2012 at 11:23pm

Hi,

I'm using SilverStripe 2.4 and the latest [url=https://github.com/mateusz/silverstripe-polls]polls module[/url] to create and manage a simple multiple choice poll on my site. What I'm trying to do, is to extend the poll choices to have couple extra fields such as an image per choice. Pretty simple stuff, just can't figure out how to get the fields to show up in admin. Here's what I have so far:

PollChoiceDecorator.php

class PollChoiceDecorator extends DataObjectDecorator {
function extraStatics() {
return array(
'db' => array(
'URL' => 'Varchar',
),
'has_one' => array(
'Image' => 'Image',
),
);
}

public function getCMSFields() {
$this->extend('updateCMSFields', $fields);
return $fields;
}

public function updateCMSFields(FieldSet $fields) {
$fields->push(new TextField('URL', 'URL address'));
$fields->push(new FileIFrameField('Image', 'Choice image'));
}
}

_config.php

// Extend PollChoice
Object::add_extension('PollChoice', 'PollChoiceDecorator');

The fields show up in db, but I can't get them to show up in the popup for a single choice. What am I doing wrong here? Is this even the right way to do this?