3

I have successfully created a gallery landing page that pulls a specified child album cover image to itself. This works perfectly in SS 4.2.1 I then created a new SS 4.3.1 and copied over all the templates. Everything is working except for this Gallery. When I am in the admin interface I can click on the gallery page and there are no error messages but when I click on the child AlbumPage page I get the following error:

[Emergency] Uncaught Error: Call to a member function scaffoldSearchField() 
on string
GET /bubbleshop/admin/pages/edit/show/48
Line 2249 in /var/www/silverstripe/bubbleshop/vendor/silverstripe/framework/src/ORM/DataObject.php

Source
2240 
2241                 // Otherwise we have a bug
2242                 } else {
2243                     user_error("Bad value for searchable_fields, 
'field' value: "
2244                         . var_export($spec['field'], true), 
E_USER_WARNING);
2245                 }
2246 
2247             // Otherwise, use the database field's scaffolder
2248             } elseif ($object = $this->relObject($fieldName)) {
2249                 $field = $object->scaffoldSearchField();
2250             }
2251 
2252             // Allow fields to opt out of search
2253             if (!$field) {
2254                 continue;
2255             }

I have managed to identify the code that is causing the error. In the private static $summary_fields I have a Boolean and this below to convert to Yes or No to but I am not sure how to fix it.

public function Cover(){
        return ($this->Cover==true ? 'Yes' : ' ');
    }

Thanks in advance for taking a look.

Best regards, Lyn

scrowler
  • 24,273
  • 9
  • 60
  • 92
  • I'm getting the same error after a Silverstripe upgrade. How did you identify the exact code causing the issue? – BaronGrivet Feb 25 '19 at 01:13
  • 1
    I had built a new instance with latest SS. Then I slowly started migrating my templates to see what works and what didn't. Then, Gallery. My nemesis. I had no idea why this error was happening so I started rebuilding each element to my templates making sure it worked before moving on and then this last section of code caused the error. Once I removed that, everything worked as expected. Took hours. I hope this helps you too. Cheers! – Lynda Smith Feb 25 '19 at 23:44

1 Answers1

3

We can use the Boolean Nice function to return a nice version of the boolean value already. Use the following and remove the custom Cover() function from your class.

private static $summary_fields = [
    'Cover.Nice',
];

private static $field_labels = [
    'Cover.Nice' => 'Cover',
];
3dgoo
  • 15,716
  • 6
  • 46
  • 58