5121 Posts in 1527 Topics by 1119 members
| Go to End | Next > | |
| Author | Topic: | 3724 Views |
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 3:38am
@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!
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 3:44am
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;
} -
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 4:21am
@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!
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 4:28am
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.
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 4:45am
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!
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 5:47am
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'); -
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 6:17am
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!
-
Re: Storing and Displaying a Collection of Testimonials

26 July 2011 at 6:57am
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;
}
| 3724 Views | ||
| Go to Top | Next > |


