Skip to content

Commit

Permalink
Merge pull request #2 from xini/mark-parent-as-changed
Browse files Browse the repository at this point in the history
mark owner object as changed when attributes are changed
  • Loading branch information
dizzystuff authored Jun 21, 2023
2 parents 99a47d0 + d2b2350 commit 45df01c
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 45df01c

Please sign in to comment.