/** * @param FieldList $fields * @return FieldList|void */ public function updateCMSFields(FieldList $fields) { $oldFields = $fields->toArray(); foreach ($oldFields as $field) { $fields->remove($field); } $fields->push(new TextField("Title", "Title")); $fields->push(new HtmlEditorField("Summary", "Summary")); $fields->push(new HtmlEditorField("Description", "Description")); $fields->push(new MemberAutoCompleteField("Curator", "Curator")); $fields->push($ddl = new DropdownField('ReleaseID', 'Release', OpenStackRelease::get()->map("ID", "Name"))); $ddl->setEmptyString('-- Select a Release --'); if ($this->owner->ID > 0) { $components_config = new GridFieldConfig_RelationEditor(100); $components = new GridField("OpenStackComponents", "Supported Release Components", $this->owner->OpenStackComponents(), $components_config); $components_config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchList($this->getAllowedComponents()); $components_config->removeComponentsByType('GridFieldAddNewButton'); //$components_config->addComponent(new GridFieldSortableRows('OpenStackSampleConfig_OpenStackComponents.Order')); $fields->push($components); $fields->push($ddl = new DropdownField('TypeID', 'Type', OpenStackSampleConfigurationType::get()->filter('ReleaseID', $this->owner->ReleaseID)->map("ID", "Type"))); $ddl->setEmptyString('-- Select a Configuration Type --'); $related_notes_config = new GridFieldConfig_RecordEditor(100); $related_notes = new GridField("RelatedNotes", "Related Notes", $this->owner->RelatedNotes(), $related_notes_config); $related_notes_config->addComponent(new GridFieldSortableRows('Order')); $fields->push($related_notes); } return $fields; }
/** * @param IOpenStackRelease $release * @return IOpenStackRelease */ public function cloneRelease(IOpenStackRelease $release) { return $this->tx_manager->transaction(function () use($release) { $clone = OpenStackRelease::create(); $index = ''; $idx = 0; do { $proposed_name = $release->Name . '-CLONE' . $index; ++$idx; $index = '-' . $idx; } while (intval(OpenStackRelease::get()->filter('Name', $proposed_name)->count()) > 0); $clone->Name = $proposed_name; $clone->Status = 'Future'; $clone->write(); //components foreach ($release->OpenStackComponents() as $component) { $clone->OpenStackComponents()->add($component); } //supported apis foreach ($release->SupportedApiVersions() as $api) { $new_api = OpenStackReleaseSupportedApiVersion::create(); $new_api->OpenStackComponentID = $api->OpenStackComponentID; $new_api->ApiVersionID = $api->ApiVersionID; $new_api->ReleaseVersion = $api->ReleaseVersion; $new_api->ReleaseID = $clone->ID; $new_api->write(); } //sample configurations foreach ($release->SampleConfigurationTypes() as $config_type) { $new_config_type = OpenStackSampleConfigurationType::create(); $new_config_type->Type = $config_type->Type; $new_config_type->Order = $config_type->Order; $new_config_type->IsDefault = $config_type->IsDefault; $new_config_type->write(); foreach ($config_type->SampleConfigurations() as $sample) { $new_sample = OpenStackSampleConfig::create(); $new_sample->Title = $sample->Title; $new_sample->Summary = $sample->Summary; $new_sample->Description = $sample->Description; $new_sample->IsDefault = $sample->IsDefault; $new_sample->Order = $sample->Order; $new_sample->CuratorID = $sample->CuratorID; $new_sample->ReleaseID = $clone->ID; $new_sample->write(); foreach ($sample->RelatedNotes() as $note) { $new_note = OpenStackSampleConfigRelatedNote::create(); $new_note->Title = $note->Title; $new_note->Link = $note->Link; $new_note->Order = $note->Order; $new_note->write(); $new_sample->RelatedNotes()->add($new_note); } foreach ($sample->OpenStackComponents() as $sample_comp) { $new_sample->OpenStackComponents()->add($sample_comp, array('Order' => $sample_comp->Order)); } $new_config_type->SampleConfigurations()->add($new_sample); } $clone->SampleConfigurationTypes()->add($new_config_type); } return $clone; }); }