diff --git a/code/editor/EditableFormField.php b/code/editor/EditableFormField.php index 81265c6..9964e9d 100755 --- a/code/editor/EditableFormField.php +++ b/code/editor/EditableFormField.php @@ -34,6 +34,7 @@ class EditableFormField extends DataObject { static $extensions = array( "Versioned('Stage', 'Live')" ); + /** * @var FieldEditor The current editor */ diff --git a/code/editor/EditableMultipleOptionField.php b/code/editor/EditableMultipleOptionField.php index fc4cbc1..f5dfa60 100644 --- a/code/editor/EditableMultipleOptionField.php +++ b/code/editor/EditableMultipleOptionField.php @@ -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 diff --git a/code/editor/EditableOption.php b/code/editor/EditableOption.php index bdb923a..1712494 100644 --- a/code/editor/EditableOption.php +++ b/code/editor/EditableOption.php @@ -21,6 +21,10 @@ class EditableOption extends DataObject { static $has_one = array( "Parent" => "EditableMultipleOptionField", ); + + static $extensions = array( + "Versioned('Stage', 'Live')" + ); /** * Template for the editing view of this option field