Skip to content

Commit

Permalink
mark owner object as changed when attributes are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
xini committed Jun 16, 2023
1 parent 99a47d0 commit d2b2350
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Extensions/Attributable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

class Attributable extends DataExtension
{
Expand Down Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d2b2350

Please sign in to comment.