@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!
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.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- 4
- 5
- Next 10 entries
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;
}
@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!
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.
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!
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');
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!
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;
}
- Previous 10 entries
- 1
- Page 22(current)
- 3
- 4
- 5
- Next 10 entries