ENHANCEMENT: added staging / versioning support for EditableOptions

This commit is contained in:
Will Rossiter 2009-09-23 01:36:52 +00:00
parent 2fd0883ea1
commit e24cd75b21
3 changed files with 45 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class EditableFormField extends DataObject {
static $extensions = array(
"Versioned('Stage', 'Live')"
);
/**
* @var FieldEditor The current editor
*/

View File

@ -22,6 +22,46 @@ class EditableMultipleOptionField extends EditableFormField {
"Options" => "EditableOption"
);
/**
* Publishing Versioning support.
*
* When publishing it needs to handle copying across / publishing
* each of the individual field options
*
* @return void
*/
public function publish($fromStage, $toStage, $createNewVersion = false) {
$live = Versioned::get_by_stage("EditableOption", "Live", "`EditableOption`.ParentID = $this->ID");
if($live) {
foreach($live as $option) {
$option->delete();
}
}
if($this->Options()) {
foreach($this->Options() as $option) {
$option->publish($fromStage, $toStage, $createNewVersion);
}
}
parent::publish($fromStage, $toStage, $createNewVersion);
}
/**
* Unpublishing Versioning support
*
* When unpublishing the field it has to remove all options attached
*
* @return void
*/
public function deleteFromStage($stage) {
if($this->Options()) {
foreach($this->Options() as $option) {
$option->deleteFromStage($stage);
}
}
parent::deleteFromStage($stage);
}
/**
* Deletes all the options attached to this field before
* deleting the field. Keeps stray options from floating

View File

@ -22,6 +22,10 @@ class EditableOption extends DataObject {
"Parent" => "EditableMultipleOptionField",
);
static $extensions = array(
"Versioned('Stage', 'Live')"
);
/**
* Template for the editing view of this option field
*/