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.

General Questions /

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

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

Link/URLField


Go to End
Reply


3 Posts   1271 Views

Avatar
Imbrondir

Community Member, 13 Posts

7 July 2011 at 11:27pm

Is there such a thing? I want to store a list of links related to a page, editable from the CMS. And it should work like the link widget in the HTMLEditor. Is this possible?

Avatar
swaiba

Forum Moderator, 1837 Posts

11 July 2011 at 10:20pm

Hi,

I'm not sure how much of this can be done exactly the same way, but I would create a DataObject like...

class MyLinkURL extends DataObject {
	static $db = array(
		'LinkURL' 		=> 'Varchar',//possibly use HTMLfield to allow creating a link in that way...
	);
}

then I'd add has_many to the Page type required, then add the has_many as a tab when editting the page

...
static $has_many = array(
	'MyLinkURLs'				=> 'MyLinkURL',
);
...
function getCMSFields() {
	$fields = parent::getCMSFields();
	$fields->addFieldToTab("Root.Content.MyLinkURLs",
		new ComplexTableField(
			$this,
			'MyLinkURLs',
			'MyLinkURLs'
		)
	);
	return $fields;
}
...

Avatar
Imbrondir

Community Member, 13 Posts

16 July 2011 at 10:27am

Thanks for the tip. I had sort of given it up already and simply faked it using virtual pages. Kind of user friendly, but the urls gets messy.

I'll look into your tip.