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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Extend member and now Email field is READONLY, but still required


Reply


6 Posts   1436 Views

Avatar
ccburns

Community Member, 74 Posts

20 April 2011 at 3:21pm

Hi All,

I have building a site where I want to extend the Member object (FamilyMember.php) to include a few more fields. I then want to create a Family DataObject which will be a $has_many relationship with FamilyMember.

Now all seems to be working correctly except for the fact that in the ModelAdmin when I go to add a FamilyMember (there is a second tab automatically created for this) the EMAIL field is set as readonly so I cannot enter an email address. So when I submit it tells me that Email is a required field and won't let me submit...

I assume this might be something to do with the relationships but I have no real idea...

Any help would be appreciated. I am sure it is just something silly that I am not doing correctly.

Thanks in advance,
Colin

FamilyMember.php

<?php
//mysite/code/FamilyMember.php
class FamilyMember extends Member {

static $db = array(
'TwitterAccount' => 'Varchar(15)',
'FacebookProfile' => "Varchar(100)",
   'RSSFeed' => "Varchar(100)",
   'Website' => "Varchar(100)",
);

static $has_one = array(
'Family' => 'Family'
);

}
?>

Family.php

<?php
//mysite/code/Family.php

class Family extends DataObject {

static $db = array(
'AccountNickName' => 'Varchar(50)',
   'MothersID' => 'Int',
   'FathersID' => 'Int',
   'WhereAreYouFrom' => 'Varchar(150)',
   'HowManyChildren' => "enum('None, One on the way, 1 Child,2 Children,3 Children,4 Children,5 Children,6 Children,7 Children, 8 Children, More than 8 Children')",
   'AgeOfYoungestChild' => 'Varchar(10)',
   'AgeOfEldestChild' => 'Varchar(10)',
   'TravelStatus' => "enum('Dreaming, Planning, On the Road, Finished')",
   'TravelDuration' => "enum('less than 1 month, 1 month, 1-3 months, 3-6 months, 6-12 months, 1-2 years, indefinite')",
   'DepartureDate' => 'Date',
   'WhenWillYouFinish' => 'Date',
   'TravelBudget' => "enum('Super Budget ( < than \$50/day), Budget (< than \$100/day), Medium (\$100 - \$200/day), Luxury ( > \$200/day)')",
   'WhatDoYouWantToAchieve' => 'Text',
   'FamilyInfo' => 'Text',
   'NorthAmerica' => 'Boolean',
   'CentralAmerica' => 'Boolean',
   'Caribbean' => 'Boolean',
   'SouthAmerica' => 'Boolean',
   'MiddleEast' => 'Boolean',
   'IndianSubcontinent' => 'Boolean',
   'SouthEastAsia' => 'Boolean',
   'NorthEastAsia' => 'Boolean',
   'AustralasiaAndPacific' => 'Boolean',
   'WesternEurope' => 'Boolean',
   'EasternEurope' => 'Boolean',
   'Africa' => 'Boolean',
'Enabled' => 'Boolean'
);

static $has_one = array(
'FamilyProfileImage' => 'Image'
);

static $has_many = array(
'FamilyMembers' => 'FamilyMember'
);

static $singular_name = 'Family';
static $plural_name = 'Families';

static $summary_fields = array(
'AccountNickName',
'WhereAreYouFrom',
'TravelStatus',
'TravelBudget'
);

static $searchable_fields = array(
'AccountNickName',
'WhereAreYouFrom',
'TravelStatus',
'TravelBudget'
);
}

?>

FamilyAdmin.php

<?php

class FamilyAdmin extends ModelAdmin {

static $managed_models = array(
'Family',
);

static $url_segment = 'families';

static $menu_title = 'Family Details';

}

?>

Avatar
ccburns

Community Member, 74 Posts

20 April 2011 at 3:33pm

Here is what the popup form looks like in the backend...

Attached Files
Avatar
ccburns

Community Member, 74 Posts

20 April 2011 at 6:05pm

Okay, call me a goose, but is this something that happens as soon as you extend or decorate the Member class?

I have a number of other installs. On a cursory look those installs where I have extended or decorated the member class have this email field set as readonly. But you can still add a member (and their email address) when I select a group and do the "Fast Entry" way where there is a set of input fields below the list of fields...

There must be a reason for it?

Curious to find out why one interface allows it and the other interface prevents it???

Any suggestions, even if it is completely obvious to all other people out there I would love to know ;)

Cheers,
Colin

Avatar
copernican

Community Member, 189 Posts

22 April 2011 at 2:54pm

Hi,

I haven't tested this but...

Perhaps it is your approach in extending the Member class. I see in FamilyMember.php you extend Member and use static $db = array();

Ideally, you should be using the extraStatics() function:

<?php

class FamilyMember extends DataObjectDecorator{

function extraStatics() {
      return array(
         'db' => array(
            'TwitterAccount' => 'Varchar(15)',
'FacebookProfile' => "Varchar(100)",
'RSSFeed' => "Varchar(100)",
'Website' => "Varchar(100)",
         ),
'has_one' => array(
'Family' => 'Family'
)
      );
   }
}
?>

and then of course in _config.php add:

Object::add_extension('Member','FamilyMember');

I've recently done some extending of the Member class and used the ForumRole class in the forum module as a starting point. I just checked the site i'm working on and the email field is working like normal.

Hope this helps.

Avatar
ccburns

Community Member, 74 Posts

23 April 2011 at 3:01pm

I have now gone back and am trying to decorate the member object rather than extend it, but now the model admin is throwing an error everytime I try to add or edit the Family item :(

Obviously I am still doing something wrong... I think I might take clean look at it.

Cheers,
Colin

Avatar
ccburns

Community Member, 74 Posts

23 April 2011 at 3:15pm

Thanks,

I had forgotten to add the has_one relationship for the Family (duhhhhh!!!)

'has_one' => array(
'FamilyMemberImage' => 'Image',
'Family' => 'Family'
),

Admittedly the Email field is still set as readonly in both the new "Family Admin" - model admin and the "Security" tabs????

I imagine this is completely unrelated to my model and is more to do with some sort of permission I have set????

Thanks again,
Colin