public function addRecord(DataObjectInterface $record, $parentFields = null)
 {
     $fields = null;
     if (!$record->canEdit()) {
         return;
     }
     $this->records->push($record);
     if (method_exists($record, 'multiEditor')) {
         $editor = $record->multiEditor();
         // add its records to 'me'
         $this->addMultiEditor($editor, $record, true);
         return;
     } elseif (method_exists($record, 'multiEditFields')) {
         $fields = $record->multiEditFields();
     } else {
         $fields = $record->getCMSFields();
     }
     /* @var $fields FieldList */
     $record->extend('updateMultiEditFields', $fields);
     // we just want the data fields, not wrappers
     $fields = $fields->dataFields();
     if (!count($fields)) {
         return;
     }
     $status = $record->CMSPublishedState;
     if ($status) {
         $status = ' (' . $status . ')';
     }
     $tab = ToggleCompositeField::create('CompositeHeader' . $record->ID, $record->Title . $status, null);
     if ($parentFields) {
         $parentFields->push($tab);
     } else {
         $tab->setStartClosed(false);
         $this->tabs->push($tab);
     }
     // if we're not using toggles, we only add the header _if_ we're an inner item, ie $parentFields != null
     if ($parentFields) {
         $this->children->push(HeaderField::create('RecordHeader' . $record->ID, $record->Title . $status));
     }
     foreach ($fields as $field) {
         $original = $field->getName();
         // if it looks like a multieditor field, let's skip for now.
         if (strpos($original, '__') > 0) {
             continue;
         }
         if ($field instanceof MultiRecordEditingField) {
             $this->addMultiEditor($field, $record, false, $tab);
             continue;
         }
         $exists = isset($record->{$original}) || $record->hasMethod($original) || $record->hasMethod('hasField') && $record->hasField($original);
         $val = null;
         if ($exists) {
             $val = $record->__get($original);
         }
         $field->setValue($val, $record);
         // tweak HTMLEditorFields so they're not huge
         if ($this->htmlEditorHeight && $field instanceof HtmlEditorField) {
             $field->setRows($this->htmlEditorHeight);
         }
         // re-write the name to the multirecordediting name for later retrieval.
         // this cannot be done earlier as otherwise, fields that load data from the
         // record won't be able to find the information they're expecting
         $name = $this->getFieldName($field, $record);
         $field->setName($name);
         if (method_exists($field, 'setRecord')) {
             $field->setRecord($record);
         }
         if ($tab) {
             $tab->push($field);
         }
         $this->children->push($field);
     }
 }