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.

Archive /

Our old forums are still available as a read-only archive.

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

There has to be a way...


Go to End


3 Posts   1124 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 July 2008 at 8:01am

I have a CurriculumDate object on a ComplexTable field. One of its components is a has_many with KeynoteSpeakers. Users choose any number of keynote speakers from checkboxes in the popup, and it works great.

But on the table, I'd like the list of selected keynote speakers to display in a comma-separated list. I tried $table->setFieldFormatting(array('KeynoteSpeakers' => '$MyCommaFunction')), but it looks like that isn't designed to take functions as variables. When I did $ID, it did give the id of the CurriculumDate, however.

I've tried a number of things. My latest hack is to use fieldCasting to cast the KeynoteSpeakers as Enum, and i've hacked the Enum fieldtype to include a function "toCSVList" that looks like this:

function toCSVList()
{
return implode(', ', $this->enumValues(false));
}

not so hot, though, and barely works.

Anything?

Avatar
Sam

Administrator, 690 Posts

14 July 2008 at 5:31pm

On the object that has the KeynoteSpeakers, create a methiod called getKeynoteSpeakersList

function getKeynoteSpeakersList() {
  foreach($this->KeynoteSpeakers() as $item) // etc
  return $something;
}

This will create a dynamic property - $obj->KeynoteSpeakersList

Which means that you can add KeynoteSpeakersList as a column to your CTF.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 July 2008 at 2:28am

Worked first try. I knew there had to be a way! Thanks, Sam!!