21303 Posts in 5736 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2991 Views |
-
Extending Member using decorator

3 January 2010 at 8:04pm
Hello.
I'm quite the noob with ss so please bear with me.
I have extended the member class using a form decorator as per this post
<?php
class ResidentMemberExt extends DataObjectDecorator {
function extraDBFields()
{
return array(
'db' => array(
'MemberType' => "Enum('Resident,Member,Associate,NonResident','Resident')",
'IsBoardMember' => "Enum('Y,N','N')",
),
);
}
public function updateCMSFields(FieldSet &$fields) {
$fields->push(new DropdownField('MemberType', 'Member Type', $this->owner->dbObject('MemberType')->enumValues()));
$fields->push(new DropdownField('IsBoardMember', 'Is a Board Member', $this->owner->dbObject('IsBoardMember')->enumValues()));
}
}Now I want to be able to add new members using the new cms fields via the cms admin panel. How to accomplish this?
-
Re: Extending Member using decorator

5 January 2010 at 12:22pm
If you apply this decorator, it will stick to the Member class, and you will have all the members decorated (even the old ones). You can't instantiate the decorator itself. If you want only some members to have the special "abilities" you have to subclass the Member instead of decorating.
Also don't forget to apply the decorator:
DataObject::add_extension('Member', 'ResidentMemberExt');
And run dev/build, this will create appropriate fields on the Members in the database.
-
Re: Extending Member using decorator

6 January 2010 at 5:11pm
Thanks for your reply. I failed to mention in my first post that I put the DataObject::add_extension('Member', 'ResidentMemberExt'); line into the config file and loaded the build url. The members table is populated with the new fields.
Given that I've updated the cms fields in the decorator, I want to know something which seems basic: how do I start adding new members via a form that is aware of the new fields? How do I create the admin interface (or can the I get at via the security tab somehow?)
-
Re: Extending Member using decorator

6 January 2010 at 5:41pm Last edited: 6 January 2010 5:42pm
Good question. Have a look at the Forum module, it does the same thing you want to accomplish. Here is excerpt from the forum/code/ForumRole.php:
function updateCMSFields(FieldSet &$fields) {
if(Permission::checkMember($this->owner->ID, "ACCESS_FORUM")) {
$fields->addFieldToTab('Root.Forum',new TextField("Nickname", "Nickname"), "FirstName");
$fields->addFieldToTab('Root.Forum',new TextField("Occupation", "Occupation"), "Surname");
$fields->addFieldToTab('Root.Forum',new CountryDropdownField("Country", "Country"), "Occupation");
$fields->addFieldToTab('Root.Forum',new ImageField("Avatar", "Upload avatar."));
$fields->addFieldToTab('Root.Forum',new DropdownField("ForumRank", "User rating", array(
"Community Member" => _t('ForumRole.COMMEMBER'),
"Administrator" => _t('ForumRole.ADMIN','Administrator'),
"Moderator" => _t('ForumRole.MOD','Moderator')
)));
}
}So change the $fields->push to $fields->addFieldToTab and see what it brings.
You may also want to add additional columns into the overview table, add something along these lines to the mysite/_config.php:
MemberTableField::addMembershipFields( array(
"Nickname" => "Nickname",
"Occupation" => "Occupation",
"Country" => "Country",
"ForumRank" => "ForumRank"
));
| 2991 Views | ||
|
Page:
1
|
Go to Top |

