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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

GridfField in Custom Widget


Go to End


687 Views

Avatar
SilverstripeLearner

Community Member, 15 Posts

5 April 2017 at 11:40pm

I have a custom widget called "CustomLinksWidget.php". In this widget I would like to give the ability to enter links and I need to use GridField. I'll type below the essential part of the code:

(CustomLinkWidget.php)
----------------------------------------------------------
private static $has_many = array(
'CustomLinks' => 'CustomLink'
);

public function getCMSFields(){
new GridField(
'CustomLinks',
'CustomLinks',
$this->CustomLinks(),
new GridFieldConfig_RelationEditor()
)
);
----------------------------------------------------------
CustomLink.php
----------------------------------------------------------
class CustomLink extends DataObject {
private static $db = array(
'Title' => 'Varchar(100)',
'URL' => 'Varchar(120)'
);

private static $has_one = array(
'CustomLinksWidget' => 'CustomLinksWidget'
);

public function getCMSFields() {
$fields = FieldList::create(
TextField::create('Title'),
TextField::create('URL')
);

return $fields;
}
}
----------------------------------------------------------

This return the following error:
Fatal error: Call to a member function FormAction() on null in D:\webserver\htdocs\clients\sarah\ncl\framework\forms\FormField.php on line 277