mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
ENHANCEMENT: added staging / versioning support for EditableOptions
This commit is contained in:
parent
2fd0883ea1
commit
e24cd75b21
@ -34,6 +34,7 @@ class EditableFormField extends DataObject {
|
||||
static $extensions = array(
|
||||
"Versioned('Stage', 'Live')"
|
||||
);
|
||||
|
||||
/**
|
||||
* @var FieldEditor The current editor
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user