/**
  * Returns a list of profile field objects after synchronising them with the
  * Member form fields.
  *
  * @return HasManyList
  */
 public function Fields()
 {
     $list = $this->getComponents('Fields');
     $fields = singleton('Member')->getMemberFormFields()->dataFields();
     $included = array();
     foreach ($list as $profileField) {
         if (!array_key_exists($profileField->MemberField, $fields)) {
             $profileField->delete();
         } else {
             $included[] = $profileField->MemberField;
         }
     }
     foreach ($fields as $name => $field) {
         if (!in_array($name, $included)) {
             $profileField = new MemberProfileField();
             $profileField->MemberField = $name;
             if (isset(self::$profile_field_defaults[$name])) {
                 $profileField->update(self::$profile_field_defaults[$name]);
             }
             $list->add($profileField);
         }
     }
     return $list;
 }
 /**
  * Get a set of all the {@link MemberProfileFields} available, automatically synced with the
  * state of the Member object.
  *
  * @return DataObjectSet
  */
 public function getProfileFields()
 {
     $set = $this->Fields();
     $fields = singleton('Member')->getMemberFormFields()->dataFields();
     $setNames = $set->map('ID', 'MemberField');
     $fieldNames = array_keys($fields);
     foreach ($set as $field) {
         if (!in_array($field->MemberField, $fieldNames)) {
             $set->remove($field);
         }
     }
     foreach ($fields as $name => $field) {
         if (in_array($name, $setNames)) {
             continue;
         }
         $profileField = new MemberProfileField();
         $profileField->MemberField = $name;
         $profileField->ProfilePageID = $this->ID;
         if (array_key_exists($name, self::$profile_field_defaults)) {
             $profileField->update(self::$profile_field_defaults[$name]);
         }
         $profileField->write();
         $set->add($profileField);
     }
     return $set;
 }