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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

[polls] SS 2.4 PollChoices DataObjectDecorator


Go to End


1115 Views

Avatar
Imploosio

Community Member, 5 Posts

27 September 2012 at 11:23pm

Hi,

I'm using SilverStripe 2.4 and the latest polls module 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?