class User extends DataObject { public function onBeforeWrite() { $this->FirstName = ucfirst($this->FirstName); $this->LastName = ucfirst($this->LastName); } }
class Customer extends DataObject { public function onBeforeWrite() { if (!$this->FirstName) { $this->FirstName = 'Unknown'; } if (!$this->LastName) { $this->LastName = 'Unknown'; } } }In this example, we have a Customer class that extends the DataObject class, and we override the onBeforeWrite method to set default values for FirstName and LastName if not provided. The package library used in this example is likely the SilverStripe ORM package, which provides the DataObject class and onBeforeWrite method.