toArray(); foreach($oldFields as $field){ $fields->remove($field); } $fields->push(new LiteralField("Title","

OpenStack Release

")); $fields->push(new TextField("Name","Name")); $date = DateField::create('ReleaseDate')->setConfig('showcalendar', true); $fields->push($date); $date->setTitle('Release Date'); $fields->push(new TextField("ReleaseNumber","Release Number")); $fields->push(new TextField("ReleaseNotesUrl","Release Notes Url")); $fields->push( new DropdownField( 'Status', 'Status', $this->owner->dbObject('Status')->enumValues() )); //components if($this->owner->ID>0){ $components_config = new GridFieldConfig_RelationEditor(); $components = new GridField("OpenStackComponents", "Supported Release Components", $this->owner->OpenStackComponents(), $components_config); $components_config->removeComponentsByType('GridFieldAddNewButton'); $fields->push($components); //supported versions //only if we have components set if($this->owner->OpenStackComponents()->filter('SupportsVersioning',true)->count()>0){ $supported_versions_config = new GridFieldConfig_RecordEditor(10); $dataColumns = $supported_versions_config->getComponentByType('GridFieldDataColumns'); $dataColumns->setDisplayFields(array( 'OpenStackComponent.Name' => 'Component', 'ApiVersion.Version'=> 'Api Version', )); //$supported_versions_config->removeComponentsByType('GridFieldEditButton'); $supported_versions = new GridField("SupportedApiVersions", "Supported Release Components", $this->owner->SupportedApiVersions(" ReleaseID = {$this->owner->getIdentifier()} AND OpenStackComponent.SupportsVersioning = 1 ")->innerJoin('OpenStackComponent','OpenStackComponent.ID = OpenStackReleaseSupportedApiVersion.OpenStackComponentID') , $supported_versions_config); $fields->push($supported_versions); } } return $fields; } public function onAfterWrite(){ parent::onAfterWrite(); //create supported versions for not versioned components $supported_components = $this->owner->OpenStackComponents(); if($supported_components && count($supported_components)>0){ $non_versioned_components = array(); foreach ($supported_components as $component) { if(!$component->getSupportsVersioning()){ //crete dumb version array_push($non_versioned_components,$component->getIdentifier()); $old = $this->owner->SupportedApiVersions(" OpenStackComponentID = {$component->getIdentifier()} AND ApiVersionID = 0 "); if(count($old)==0){ $new_supported_version = new OpenStackReleaseSupportedApiVersion; $new_supported_version->OpenStackComponentID = $component->getIdentifier(); $new_supported_version->ReleaseID = $this->owner->getIdentifier(); $new_supported_version->ApiVersionID = 0; $new_supported_version->write(); } } } $to_delete=""; if(count($non_versioned_components)>0){ $to_delete = implode(',',$non_versioned_components); $to_delete = "AND OpenStackComponentID NOT IN ({$to_delete})"; } DB::query("DELETE FROM OpenStackReleaseSupportedApiVersion WHERE ReleaseID = {$this->owner->getIdentifier()} AND ApiVersionID = 0 {$to_delete}"); } } function getCMSValidator() { return $this->getValidator(); } function getValidator() { $validator= new RequiredFields(array('Name','ReleaseNumber','ReleaseDate')); return $validator; } }