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.

Widgets /

Discuss SilverStripe Widgets.

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

Linking Dataobjects in Widget


Go to End


2196 Views

Avatar
Azlein

Community Member, 5 Posts

17 February 2013 at 3:08am

Hi,

I'm trying to link some DataObjects to a Widget. In my particular case, I have

	static $has_many = array(
		'Buttons' => 'SocialButton'
	);

in my Widget and

	static $has_one = array(
		'Icon'=>'Image',
		'Widget'=>'SocialMediaWidget'
	);

in my DatabObject.

I'm trying to do this with a GridField, but this fails:

                $fields = parent::getCMSFields();
		$gridField = GridField::create('Buttons', 'Some text', $this->Buttons(), new GridFieldConfig_RelationEditor());//new GridField("Buttons", "Buttons", $this->Buttons(), $gridFieldConfig);
		$fields->push($gridField); //This line causes a Internal Server Error

So, my question is - is it allowed to use a GridField in a Widget? If yes, why is the $fields->push call creating the error? If not, are there any alternatives?

Thanks in advance.