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.

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.

Data Model Questions /

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

DataObjectDecorator and scaffoldSearchFields


Go to End


2 Posts   2719 Views

Avatar
wildflower1975

Community Member, 63 Posts

25 February 2010 at 5:39pm

Has anybody tried to make a Custom Search field on a Member Role Decorator?

I've got a custom MemberRole extends DataObjectDecorator

and the updateForumFields functions all work sweet.

Now I want to have my Suburb field shown as a DropdownField instead of a TextField in a default search.

function extraStatics() {
return array( 'db' => array(
'Suburb' => 'Varchar',
'City' => 'Varchar'),
'searchable_fields' => array( 'FirstName','Surname','Suburb','City' ),
);

This bit works and shows the Suburb and City fields as text boxes.

I'm getting the "build the Search form" function to call the following function (in the Role Decorator .php ) and it barfs on the

$context = parent::getDefaultSearchContext();

line with [User Error] Uncaught Exception: Object->__call(): the method 'scaffoldsearchfields' does not exist on 'MemberRole'

public function getCustomSearchContext(){

$context = parent::getDefaultSearchContext();
$context->removeFieldByName('Suburb');
$suburbs = self::get_suburbs();

if($suburbs){
$suburbMap = array_combine($suburbs, $suburbs);
}else{
$suburbMap = null;
}

$suburbField = new DropDownField( 'Suburb', 'Suburb', $suburbMap);
$suburbField->sethasEmptyDefault(true);
$context->addField($suburbField);
return $context;
}

Do i need to rewrite/copy the scaffoldsearchfields function (which sounds wrong) or am I just calling it incorrectly?

Avatar
Ingo

Forum Moderator, 801 Posts

25 March 2010 at 10:31pm

Try $context = $this->owner->getDefaultSearchContext(); instead :)