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.

Customising the CMS

Add field to "Edit User"


Reply

3 Posts   1274 Views

Avatar
DeklinKelly

18 August 2010 at 9:40am Community Member, 197 Posts

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

18 August 2010 at 11:50am Community Member, 30 Posts

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

18 August 2010 at 12:09pm Community Member, 197 Posts

Works perfectly, thanks!