setValue('lastName', $value); _setName(); // replacing code to update the name field into one generic function } public function _setFirstName($value) { $this->setValue('firstName', $value); _setName(); } // new function to set the name based on lastName, firstName and the NEW middleName fields public function _setName() { $firstName = $this->get('firstName'); // @TODO: should we also test existence of middleName field to avoid errors ??? $middleName = $this->get('middleName'); $lastName = $this->get('lastName'); $name = ''; if (!empty($firstName)) { $name = $firstName . ' '; } if (!empty($middleName)) { $name = $name . $middleName . ' '; } if (!empty($lastName)) { $name = $name . $lastName; } $name = trim($name); $this->setValue('name', $name); } }