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   1134 Views

Avatar
klikhier

Community Member, 150 Posts

26 October 2010 at 1:26am

Edited: 26/10/2010 1:27am

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

Community Member, 164 Posts

28 October 2010 at 12:52am

Edited: 28/10/2010 12:53am

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

Community Member, 150 Posts

30 October 2010 at 2:19am

Edited: 30/10/2010 2:33am

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

Community Member, 150 Posts

30 October 2010 at 2:59am

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

Community Member, 164 Posts

30 October 2010 at 3:20am

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

Avatar
Willr

Forum Moderator, 5513 Posts

30 October 2010 at 6:31pm

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

Community Member, 164 Posts

30 October 2010 at 10:42pm

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