I am using a has_one to assign a banner to a page. To try and keep things organised, I am using onBeforePublish to drop the image into a banners folder. The issue is, if I publish the page without uploading an image, then a blank record labeled "new image" appears on the assets page. I've added all the conditionals I can think of, but the blank records are still being created. Any suggestions?
if($this->Banner())
{
$banner = $this->Banner();
$folder = Folder::findOrMake("Uploads/banner");
$banner->setParentID($folder->ID);
if($banner->Title != "new image")
{
$banner->write();
}
}