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

extraFields in GridFields making crazy things


Go to End


1059 Views

Avatar
Bereusei

Community Member, 96 Posts

4 March 2014 at 11:06pm

Edited: 04/03/2014 11:07pm

Hey guys,

I´ve working with many_many_extraFields to generate TextFields in related DataObjects.
But after setting the extraFields, I can´t call the variables in the related object (like: $this->ID, $this->Title).

MyParent.php

class MyParent extends DataObject{
	private static $db = array(
		"Title" => "Varchar(255)"
	);

	static $many_many = array(
		'MyChildren' => 'MyChild'
	);

	public static $many_many_extraFields = array(
        'MyChildren' => array('Foo' => 'Varchar(255)')
    );

	public function getCMSFields(){
		$fields = parent::getCMSFields();
		
		$config = GridFieldConfig_RecordEditor::create();
		$childrenFields = singleton('MyChild')->getCMSFields();
        $childrenFields->addFieldToTab('Root.Main', TextField::create('ManyMany[Foo]', 'Foo'));
		$config->getComponentByType('GridFieldDetailForm')->setFields($childrenFields);

		$gridfield = new GridField("MyChildren", "MyChild", $this->MyChildren(), $config);
		
		$fields->addFieldToTab("Root.Main", $gridfield);




		return $fields;
	}
}

MyChild.php

class MyChild extends DataObject{
	private static $db = array(
		"Title" => "Varchar(255)"
	);

	private static $belongs_many_many = array(
		"MyParents" => "MyParent"
	);

	public function getCMSFields(){
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Main", new LiteralField("Foo", $this->ID));
		return $fields;
	}
}

Has anyone a solution or a workaround?