Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Why don't my chosen fields in $summary_fields show?

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

Page: 1
Go to End
Author Topic: 437 Views
  • Spaghetti
    Avatar
    Community Member
    31 Posts

    Why don't my chosen fields in $summary_fields show? Link to this post

    I'm almost there with my staff/departments page, I just can't seem to get the summary fields that I want to be displayed, displayed. Which is odd because they were working a while ago, complete with a proper thumbnail image, which also seems to be broken now. I've tried rebuilding and flushing.

    Here's the code:

    <?php

    class StaffPage extends Page {

       public static $has_many = array(
       'StaffMembers' => 'StaffMember',
       'Departments' => 'Department'
       );
          
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          //Configures the editor for adding and removing staff.
          $gridFieldConfig =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
          $gridfield = new GridField("StaffMembers", "StaffMember", $this->StaffMembers(), $gridFieldConfig);
          $dataColumns = $gridfield->getConfig()->getComponentByType('GridFieldDataColumns');
       $dataColumns->setDisplayFields(array(
             'Name'=>'Name',            
             'Image' => 'Image',         
             ));
          $fields->addFieldToTab('Root.Staff', $gridfield);

          //Configures the editor for adding and removing Departments.
          $gridFieldConfig2 =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
          $gridfield2 = new GridField("Departments", "Department", $this->Departments(), $gridFieldConfig2);
          $dataColumns2 = $gridfield2->getConfig()->getComponentByType('GridFieldDataColumns');
       $dataColumns2->setDisplayFields(array(
             'Name'=>'Name',
             ));
          $fields->addFieldToTab('Root.Departments', $gridfield2);

          return $fields;
       }
    }

    class StaffPage_Controller extends Page_Controller {   
    }

    <?php

    class StaffMember extends DataObject {

       static $db = array(
          'Name'=>'Varchar',   
          'Details'=>'HTMLText'
       );

       static $has_one = array(
          'Image' => 'Image',      
          'Department' => 'Department',
          "Parent" => "StaffPage"
       );

       static $summary_fields = array(       
          'Name',
          'Thumbnail',
          'Department.Name'
       );

       function getThumbnail() {
          return $this->Image()->CMSThumbnail();
       }

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeByName('ParentID');
          return $fields;
       }
    }

    StaffMember seems to show the Name and Image summary fields, in that order, no matter what I put there, which suggests to me that it's ignoring my choice entirely.

    Any ideas? Much appreciated...

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: Why don't my chosen fields in $summary_fields show? Link to this post

    You've specified the fields to be displayed in your getCMSFields() function:

    $dataColumns->setDisplayFields(array(
    'Name'=>'Name',
    'Image' => 'Image'
    ));

    Either update that section of code to match what fields you want, or just remove it.

  • Spaghetti
    Avatar
    Community Member
    31 Posts

    Re: Why don't my chosen fields in $summary_fields show? Link to this post

    Gah... you're right. 'Target fixation'.

    Thanks again.

  • Spaghetti
    Avatar
    Community Member
    31 Posts

    Re: Why don't my chosen fields in $summary_fields show? Link to this post

    Actually, it's displaying properly on the live site now but in the cms not all of my staff are showing.

    There's two main tabs on the staff page, departments and staff.

    If I add staff via the staff tab they show up in that main tab okay but if I add them via the departments->members sub-tab, they don't show up in the main staff tab, yet they seem to be correctly linked to the department and show on the site correctly.

    437 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.