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

many_many widget


Go to End


1340 Views

Avatar
jam13

121 Posts

18 October 2007 at 6:13am

I'm trying to create a widget that has a many_many relationship with a page type:

class RecipeWidget extends Widget {
static $many_many = array(
'FeaturedRecipes' => 'RecipePage'
);

class RecipePage extends Page {
static $belongs_many_many = array(
'RecipeWidgets' => 'RecipeWidget'
);

This seems to work (it creates the appropriate tables), so I tried to add a checkbox set to the CMSFields:

class RecipeWidget extends Widget {
...
function getCMSFields() {
$myRecipes = DataObject::get('RecipePage');
return new FieldSet(
new CheckboxSetField('FeaturedRecipes', '', $myRecipes)
);
...

which displays the checkbox set as requested. Unfortunately it doesn't save the selections :(

Am I doing something wrong, or does this Field not work within a Widget?