Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Storing and Displaying a Collection of Testimonials

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

Page: 1 2 3 4 5
Go to End
Author Topic: 4440 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    @martimiz - Thanks for the suggestion! I had actually tried that and I still have the same problem. The database stops rebuilding as soon as it hits the Category table. Thanks anyway!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    what error do you see?

    these are my two "wrapper functions" for converting to a multiselect

    public static function ChangeManyManyFieldToMultiSelect($doCurrent, $fields,$strTabName,$strDataObjectName,$strFieldName,$strInsertAfterFieldName,$strOptionTextField='Name',$filter='', $controller = null) {
          $fields->removeFieldFromTab('Root',$strTabName);
          $dos = DataObject::get($strDataObjectName,$filter);
          $map = $dos ? $map = $dos->toDropdownMap('ID',$strOptionTextField) : array();
          $fields->insertBefore(new MultiSelectField($strFieldName,$strTabName, $map),$strInsertAfterFieldName);
          return $fields;
    }

    public static function ChangeManyManyFieldToMultiSelectAddToTab($doCurrent, $fields,$strTabName,$strDataObjectName,$strFieldName,$strAddToTab,$strOptionTextField='Name',$filter='') {
          $fields->removeFieldFromTab('Root',$strTabName);
          $dos = DataObject::get($strDataObjectName,$filter);
          $map = $dos ? $map = $dos->toDropdownMap('ID',$strOptionTextField) : array();
          $fields->addFieldToTab($strAddToTab, new MultiSelectField($strFieldName,$strTabName, $map));
          return $fields;
    }

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    @swaiba - Thanks for your reply. I turned on dev mode in my config file and don't see any errors when I rebuild the database. It just stops at the category table.

    Are you saying I need to use something like the code you just shared instead of this...
    $source = DataObject::get('Category');
    new MultiSelectField(
    "Categories", // Relationship
    "Testimonial Categories", // Field name
    $source->map('ID','Title') // Source records (array)
    );

    ...if so I may have some questions.

    Thanks for your help!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    well that code fragment is simply not going to compile (I know you have lifted it from http://silverstripe.org/multiselectfield-module/, but it does expect some knowledge as how to use it).

    Instead I've given you exactly what I use to implement it - Whenever I do the same 3/4 lines over and again I make it into a function.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    Thanks for bearing with me! To make sure I understand correctly, that "$source=" code snippet will still go into my Testimonial.php file, right?

    I then need to add the two functions you shared to my code. Do these belong in MultiSelectField.php file or somewhere else? And I can use them exactly as they are or do I need to change anything?

    Thanks!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    that "$source=" code snippet will still go into my Testimonial.php file, right?

    no, but I think I should have provided a better example... try this... it is to replace that $source= code

    $fields->removeFieldFromTab('Root','Categories');
    $dos = DataObject::get('Category ');
    $map = $dos ? $map = $dos->toDropdownMap() : array();
    $msf = new MultiSelectField("Testimonial Categories",'Categories', $map);
    $fields->insertAfter($msf,'Title');

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    thanks swaiba! does the code snippet that you just shared still needs to go inside of a function? because it doesn't appear to work on its own.

    thanks again!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    yes of course...

    function getCMSFields() {
       $fields = parent::getCMSFields();

       $fields->removeFieldFromTab('Root','Categories');
       $dos = DataObject::get('Category ');
       $map = $dos ? $map = $dos->toDropdownMap() : array();
       $msf = new MultiSelectField("Testimonial Categories",'Categories', $map);
       $fields->insertAfter($msf,'Title');

       return $fields;
    }

    4440 Views
Page: 1 2 3 4 5
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.