Silverstripe 4.3
I’'m managing a dataobjet with the gridfield componenet. DataObject (DO) has a has_one relation to image.
Strangely when going into editing a DO, the image that is shown is always the one from the first DO I edited. I need to press F5 to get the right image. If I save the DO without refreshing, the Image from the first DO that I edited is linked to the current DO… ???
The DataObject:
namespace Schrattenholz\Test;
use Page;
use Silverstripe\ORM\DataObject;
use SilverStripe\Assets\Image;
class DObject extends DataObject{
private static $table_name="dobject";
private static $has_one=[
'Bild'=>Image::class,
'Page'=>Page::class
];
private static $owns=[
'Bild'
];
public function onAfterWrite()
{
parent::onAfterWrite();
if ($this->Bild()->exists() && !$this->Bild()->isPublished())
{
$this->Bild()->doPublish();
}
}
}
The PageType:
namespace Schrattenholz\Test;
use Page;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
class Test extends Page{
private static $db=[];
private static $has_many=[
'Objects'=>DObject::class
];
public function getCMSFields(){
$fields=parent::getCMSFields();
$fields->addFieldToTab('Root.Objects', GridField::create(
'Objects',
'Objects on this page',
$this->Objects(),
GridFieldConfig_RecordEditor::create()
));
return $fields;
}
}