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.

Forum Module

Discuss the Forum Module.

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

Extend ForumRole


Reply

7 Posts   1108 Views

Avatar
klikhier

26 October 2010 at 1:26am (Last edited: 26 October 2010 1:27am), Community Member, 150 Posts

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

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?

Avatar
MarijnKampf

28 October 2010 at 12:52am (Last edited: 28 October 2010 12:53am), Community Member, 164 Posts

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.

Avatar
klikhier

30 October 2010 at 2:19am (Last edited: 30 October 2010 2:33am), Community Member, 150 Posts

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

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
}
}
?>

Avatar
klikhier

30 October 2010 at 2:59am Community Member, 150 Posts

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;

}
}

?>

Avatar
MarijnKampf

30 October 2010 at 3:20am Community Member, 164 Posts

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

Avatar
Willr

30 October 2010 at 6:31pm Forum Moderator, 5511 Posts

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.

Avatar
MarijnKampf

30 October 2010 at 10:42pm Community Member, 164 Posts

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