From d2b2350e74d9f272b5cccfb058faeaf0ff909aa0 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Fri, 16 Jun 2023 14:26:18 +1000 Subject: [PATCH] mark owner object as changed when attributes are changed --- src/Extensions/Attributable.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Extensions/Attributable.php b/src/Extensions/Attributable.php index 3f0046a..278dd54 100644 --- a/src/Extensions/Attributable.php +++ b/src/Extensions/Attributable.php @@ -10,6 +10,7 @@ use SilverStripe\Forms\HiddenField; use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; +use SilverStripe\Versioned\Versioned; class Attributable extends DataExtension { @@ -147,6 +148,12 @@ public function detachAttribute($attribute) $existing = Attribution::get_from_pair($this->owner, $attribute); if ($existing) { $this->owner->Attributions()->remove($existing); + // mark owner as changed + if ($this->owner->hasExtension(Versioned::class)) { + $this->owner->writeToStage(Versioned::DRAFT); + } else { + $this->owner->write(); + } } } @@ -175,6 +182,12 @@ public function attachAttribute($attribute) $attribution->write(); $this->owner->Attributions()->add($attribution); + // mark owner as changed + if ($this->owner->hasExtension(Versioned::class)) { + $this->owner->writeToStage(Versioned::DRAFT); + } else { + $this->owner->write(); + } return $attribution; }