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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

List has_many-object's title as column on DOM


Go to End


2 Posts   1358 Views

Avatar
ROlckers

Community Member, 8 Posts

2 November 2011 at 12:55pm

Good day,

I have a data object manager loaded on a page as per below:

class XYZPage extends Page
{
	static $has_many = array (
		'CustomModels' => 'CustomModel'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.CustomWidgets", new DataObjectManager(
			$this,
			'CustomModels',
			'CustomModel',
			array('CustomName'=>'Custom Model Name', 'CustomParentPageID'=>'Custom Parent Page ID'),
			'getCMSFields_forPopup'
		));
		return $fields;
	}
}

class CustomModel extends DataObject
{
	static $db = array (
		'CustomName' => 'varchar(255)'
	);
	
	static $has_one = array (
		'CustomParentPage' => 'SiteTree'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('WidgetName', 'Widget Name'),
			new SimpleTreeDropdownField('CustomParentPageID', 'Parent Page', 'SiteTree')
		);
	}
}

The CustomModel has a one to one relationship with the SiteTree table (CustomParentPage). In the getCMSFields function (XYZPage) I can print the CustomParentPageID as a column in the DOM. Is it possible to add that page Title (or other properties related to that class) in the DOM? If so would someone mind steering me in the right direction?

I would ideally like to do something similar to this:

		$fields->addFieldToTab("Root.Content.CustomWidgets", new DataObjectManager(
			$this,
			'CustomModels',
			'CustomModel',
			array('CustomName'=>'Custom Model Name', 'CustomParentPageID'=>'Custom Parent Page ID',
				'CustomParentPage->Title'=>'Custom Parent Page Title'  //   <-- is something like this possible?
			),
			'getCMSFields_forPopup'
		));

Avatar
ROlckers

Community Member, 8 Posts

4 November 2011 at 11:15am