public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     // Remove MCListSegment GridField Tab And Manually Manage
     $fields->removeByName("MCListSegments");
     // Manually Manage Creation of MCListSegments Based on Selected MCLists
     if (empty($this->owner->ID)) {
         $lists = new DataList("MCList");
         if ($lists->count() > 1) {
             $fields->addFieldToTab('Root.Main', new LiteralField('_AffectedMCListsTitle', '<h2>Affected MailChimp Lists</h2>'));
             $map = $lists->map("ID", "Name");
             $listIDs = new CheckboxSetField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', $map);
             $listIDs->setDefaultItems(array_keys($map->toArray()));
         } else {
             if ($lists->count() == 1) {
                 $listIDs = new HiddenField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', $lists->first()->ID);
             } else {
                 $listIDs = new HiddenField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', 0);
             }
         }
         $fields->addFieldToTab('Root.Main', $listIDs);
     }
     // Configure Attendees Gridfield
     $gf = $fields->fieldByName('Root.Attendees.Attendees');
     if (is_object($gf) && $gf->exists()) {
         $gf->setList($this->getMyManyManyComponents('Attendees'));
         $config = $gf->getConfig();
         $config->removeComponentsByType('GridfieldAddNewButton');
     }
     return $fields;
 }
 /**
  * Usage: Find the copied ("NEW") equivalent of the old has-one relation and attach it to the newObject ...
  * @param DataObject $copyFrom
  * @param DataObject $newObject
  * @param String $hasOneMethod - the fieldname (method) of the has one relations (e.g. MyOtherDataObject)
  * @param DataList $dataListToChooseFrom
  *
  * @return CopyFactory
  */
 public function attachToMoreRelevantHasOne($copyFrom, $newObject, $hasOneMethod, $dataListToChooseFrom)
 {
     $fieldNameWithID = $hasOneMethod . "ID";
     if ($this->recordSession) {
         self::add_to_session("\n\t\t\t\t\t====================================\n\t\t\t\t\tATTACH TO MORE RELEVANT HAS-ONE\n\t\t\t\t\tFIELD {$hasOneMethod}\n\t\t\t\t\tOBJECTS TO CHOOSE FROM: " . $dataListToChooseFrom->sql() . "\n\t\t\t\t\t====================================\n\t\t\t\t", $copyFrom, $newObject);
     }
     if ($copyFrom->{$fieldNameWithID}) {
         //find out field to choose from
         $firstObject = $dataListToChooseFrom->first();
         if ($firstObject) {
             $dataListToChooseFrom = $dataListToChooseFrom->filter(array($firstObject->CopiedFromFieldName($withID = true) => $copyFrom->{$fieldNameWithID}))->Sort("Created DESC");
             $count = $dataListToChooseFrom->count();
             if ($count == 1 && ($newAttachment = $dataListToChooseFrom->First())) {
                 if ($this->recordSession) {
                     self::add_to_session("Found Matching record.", $copyFrom, $newObject);
                 }
                 if ($this->isForReal) {
                     $newObject->{$fieldNameWithID} = $newAttachment->ID;
                     $newObject->write();
                 }
             } else {
                 if ($this->recordSession) {
                     if ($count > 1) {
                         self::add_to_session("ERROR: found too many Matching records.", $copyFrom, $newObject);
                     } elseif ($count == 0) {
                         self::add_to_session("ERROR: Could not find any Matching records.", $copyFrom, $newObject);
                     } else {
                         self::add_to_session("ERROR: There was an error retrieving the matching record.", $copyFrom, $newObject);
                     }
                 }
                 if ($this->isForReal) {
                     $newObject->{$fieldNameWithID} = 0;
                     $newObject->write();
                 }
             }
         } else {
             self::add_to_session("ERROR: Could not find any Matching records from base DataList.", $copyFrom, $newObject);
             $newObject->{$fieldNameWithID} = 0;
             $newObject->write();
         }
     } else {
         if ($this->recordSession) {
             self::add_to_session("copyFrom object does not have a value for: {$fieldNameWithID}", $copyFrom, $newObject);
         }
     }
     if ($this->recordSession) {
         self::add_to_session("*** END OF attachToMoreRelevantHasOne ***", $copyFrom, $newObject);
     }
     return $this;
 }