Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Add field to "Edit User"

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

Page: 1
Go to End
Author Topic: 1171 Views
  • DeklinKelly
    Avatar
    Community Member
    196 Posts

    Add field to "Edit User" Link to this post

    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;

       }

    }

    ?>

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Add field to "Edit User" Link to this post

    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 <°(((-<

  • DeklinKelly
    Avatar
    Community Member
    196 Posts

    Re: Add field to "Edit User" Link to this post

    Works perfectly, thanks!

    1171 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.