From 58abd268ff0747757702c0d03fe09d4c52ed0651 Mon Sep 17 00:00:00 2001 From: Michal Kleiner Date: Fri, 18 Jun 2021 20:09:35 +1200 Subject: [PATCH] Ensure joining object is published on write for non-versioned owner objects --- src/Models/DataObjectTaxonomyTerm.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Models/DataObjectTaxonomyTerm.php b/src/Models/DataObjectTaxonomyTerm.php index 64a63d1..1458138 100644 --- a/src/Models/DataObjectTaxonomyTerm.php +++ b/src/Models/DataObjectTaxonomyTerm.php @@ -49,4 +49,22 @@ public function onBeforeDelete() } } } + + + /** + * Ensure the linking object is published to Live stage after writing the owner object that doesn't have versioning. + */ + public function onAfterWrite() + { + parent::onAfterWrite(); + + // explicit comparison to false as using ! may not be obvious enough in this case + if ($this->OwnerObject() && $this->OwnerObject()->hasExtension(Versioned::class) === false) { + if (Versioned::get_stage() === Versioned::DRAFT) { + if ($this->canPublish()) { + $this->doPublish(); + } + } + } + } }