Can anyone give me a code example or a link showing how to extend a member object to have additional fields using a DataObjectDecorator? As simple as you have got.
Thanks
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
check the forum's ForumRole.php
Have you checked the docs? A lot of info in there.
In the ForumRole decorator there is reference to a table ForumMember in a function called augmentDatabase.
I don't see that table. What is this all about?
function augmentDatabase() {
$exist = DB::query( "SHOW TABLES LIKE 'ForumMember'" )->numRecords();
if( $exist > 0 ) {
DB::query( "UPDATE `Member`, `ForumMember` " .
"SET `Member`.`ClassName` = 'Member'," .
"`Member`.`ForumRank` = `ForumMember`.`ForumRank`," .
"`Member`.`Occupation` = `ForumMember`.`Occupation`," .
"`Member`.`Country` = `ForumMember`.`Country`," .
"`Member`.`Nickname` = `ForumMember`.`Nickname`," .
"`Member`.`FirstNamePublic` = `ForumMember`.`FirstNamePublic`," .
"`Member`.`SurnamePublic` = `ForumMember`.`SurnamePublic`," .
"`Member`.`OccupationPublic` = `ForumMember`.`OccupationPublic`," .
"`Member`.`CountryPublic` = `ForumMember`.`CountryPublic`," .
"`Member`.`EmailPublic` = `ForumMember`.`EmailPublic`," .
"`Member`.`AvatarID` = `ForumMember`.`AvatarID`," .
"`Member`.`LastViewed` = `ForumMember`.`LastViewed`" .
"WHERE `Member`.`ID` = `ForumMember`.`ID`"
);
echo("<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('ForumRole.TRANSFERSUCCEEDED','The data transfer has succeeded. However, to complete it, you must delete the ForumMember table. To do this, execute the query \"DROP TABLE \'ForumMember\'\".') . "</div>" );
}
}
I have a much simpler example:
===mysite/code/MyMemberExtension===
<?php
class MyMemberExtension extends DataObjectDecorator {
function extraDBFields() {
return array(
'db' => array(
'Website'=>'Varchar'
),
'has_one' => array(
'Avatar' => 'Image'
),
);
}
public function updateCMSFields(FieldSet &$fields) {
$fields->push(new TextField('Website', 'Website-URL'));
$fields->push(new ImageField('Avatar', 'Profile Image'));
}
}
?>
===
In mysite/_config.php:
Object::add_extension('Member', 'MyMemberExtension');
Thanks for responding adiwidjaja.
That is a much simpler example. Also pointing out the _config.php inclusion is good too as this is how the system knows of the decorator's existence. The forum code takes days to ponder.
Do you happen to know what is going on in the ForumRole function augmentDatabase() and the ForumMember table reference?