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.

Customising the CMS /

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

Add field to "Edit User"


Go to End


3 Posts   1748 Views

Avatar
DeklinKelly

Community Member, 197 Posts

18 August 2010 at 9:40am

I want to add a field to the "Edit User" area.

sapphire/security/member.php needs to be extended.

I created a file in the mysite folder but it does NOT work.

How can I add a field?

<?php

class UserCustom extends Member  {

	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Foobar', new LiteralField('CustomCodeFoobar','<h3>Foobar</h3>'));
		return $fields;

	}

}

?>

Avatar
Zauberfisch

Community Member, 30 Posts

18 August 2010 at 11:50am

blubb

create a new File "MyMemberExtension.php" in the folder mysite

class MyMemberExtension extends DataObjectDecorator {

	/**
	 * Define extra database fields
	 *
	 * Return an map where the keys are db, has_one, etc, and the values are
	 * additional fields/relations to be defined
	 */
	function extraStatics() {
		$fields = array(
			'db' => array(
				'MyExtraDBField' => 'Text'
			),
			'has_one' => array(
			),
			'defaults' => array(
				'MyExtraDBField' => 'awesome default text'
			)
		);
		return $fields;
	}

	function updateCMSFields(FieldSet &$fields) {
		$fields->addFieldToTab('Root.Foobar', new TextField("MyExtraDBField", "My Extra DB Field"));
	}
}

and then add the following line to your "mysite/_config.php"

DataObject::add_extension('Member', 'MyMemberExtension ');

i hope that is what you are searching for, and i hope it works, i kinda copied it from the Forum Module but didn't tested it

greetings <°(((-<

Avatar
DeklinKelly

Community Member, 197 Posts

18 August 2010 at 12:09pm

Works perfectly, thanks!