Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » There has to be a way...

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

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

Page: 1
Go to End
Author Topic: 856 Views
  • UncleCheese
    Avatar
    4085 Posts

    There has to be a way... Link to this post

    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?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: There has to be a way... Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: There has to be a way... Link to this post

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

    856 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.