Jump to:

1036 Posts in 810 Topics by 315 members

Forum Module

SilverStripe Forums » Forum Module » Extend ForumRole

Discuss the Forum Module.

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

Page: 1
Go to End
Author Topic: 1097 Views
  • klikhier
    Avatar
    Community Member
    150 Posts

    Extend ForumRole Link to this post

    Hi, I'm trying to extend the ForumRole as described here http://doc.silverstripe.org/modules:forum.

    However with the code below (and DataObject::add_extension('Member', 'CustomForumRole'); in _config.php), the form on the front-end (ForumMemberProfile/edit) is not being updated

    <?php

    class CustomForumRole extends DataObjectDecorator {

       function extraStatics() {
          return array(
             'db' => array(
                'CustomDatabaseField' => 'Text',
             )
          );
       }
          
       function getForumFields() {
    $fieldset = new FieldSet(
    new TextareaField('CustomDatabaseField')
    );

    return $fieldset;
       }
       
       function updateCMSFields(&$fields) {

          $tabset = $fields->findOrMakeTab('Root.Main');
    $tabset->push(new TextareaField('CustomDatabaseField'));

       }

    }
    ?>

    What is missing?

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Extend ForumRole Link to this post

    I don't think the getForumFields function is actually being called from ForumMemberProfile. Not sure why not. The extra field is being added to the CMS Member section.

    function getForumFields($showIdentityURL, $addmode) {
        Debug::Show("HI");
        $fieldset = parent::getForumFields($showIdentityURL, $addmode);

          $fieldset.push(new FieldSet(new TextareaField('CustomDatabaseField')));

    return $fieldset;
    }

    The show debug code is never executed in my test.

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Extend ForumRole Link to this post

    Thanks Marijn, you're right! Means that the Forum documentation is not correct http://doc.silverstripe.org/modules:forum.

    It should be:

    <?php

    class CustomForumRole extends DataObjectDecorator {

    function extraStatics() {
    // To modify the fields of the database
    }

    function updateForumFields() {
    // To modify the forum member form (registration) of the forum
    }

    function updateCMSFields() {
    // To modify the forum member view of the popup window in the CMS part
    }
    }
    ?>

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Extend ForumRole Link to this post

    Ok, here it is (special thanks to Martijn and Marijn):

    <?php

    // mysite/code/CustomForumRole.php

    class CustomForumRole extends DataObjectDecorator {

       function extraStatics() {
          return array(
             'db' => array(
                'CustomField' => 'Text'
             )
          );
       }

       function updateForumFields(FieldSet $fields) {

       // Add CustomField to Frontend
          $fields->push(new TextField('CustomField'));
          return $fields;

       }

    public function updateCMSFields(FieldSet $fields) {
       
          // Add CustomField to CMS
          $fields->addFieldToTab('Root.Main',new TextField('CustomField));
          return $fields;

    }
    }

    ?>

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Extend ForumRole Link to this post

    Was just about to add a comment to the documentation, but saw that you beat me to it

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: Extend ForumRole Link to this post

    The documentation *is* a wiki which does allow you to edit the actual page content yourself so feel free to fix bugs as you find them.

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Extend ForumRole Link to this post

    I did try to edit the page, but all I saw was: "This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. "

    1097 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.