We can create get functions in our custom DataObject to return any content we like. These functions can be used in many places, including the map function.
Here's how to add the getFullName function to return the FullName string to our object:
class Teacher extends DataObject { // ... public function getFullName() { return $this->FirstName . ' ' . $this->LastName; } }
Then in our DropdownField we can get Teacher::get()->map('ID', 'FullName') like this:
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab('Root.Main', array( DropdownField::create('TeacherID', 'Teacher') ->setSource(Teacher::get()->map('ID', 'FullName')) ->setEmptyString('Select a teacher') ); return $fields; }
3dgoo source share