Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObjectDecorator and scaffoldSearchFields

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

Page: 1
Go to End
Author Topic: 1492 Views
  • wildflower1975
    Avatar
    Community Member
    59 Posts

    DataObjectDecorator and scaffoldSearchFields Link to this post

    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?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: DataObjectDecorator and scaffoldSearchFields Link to this post

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

    1492 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.