-
Notifications
You must be signed in to change notification settings - Fork 682
Closed
Labels
Description
What happened?
Description
When applying changes to my entry via EVENT_BEFORE_SAVE it does not propagate these changes on the first save (vendor/craftcms/cms/src/services/Drafts.php:402). This is unexpected behaviour since saving the second time does propagate.
Steps to reproduce
- Create a section that is applied to at least two sites.
- Create two fields that are both non-translatable (in this case
productPriceWebshopandproductPriceRetail). - Use this little sample script, it applies the value of
productPriceRetailtoproductPriceWebshoponly whenproductPriceWebshophas a falsely value.
Event::on(Entry::class, Element::EVENT_BEFORE_SAVE, function ($event) {
$entry = $event->sender;
if (! $entry instanceof Entry) {
return;
}
if (ElementHelper::isDraftOrRevision($entry)) {
return;
}
$section = $entry->section;
if (! $section) {
return;
}
if ($section->handle === 'products') {
if (! $entry->productPriceWebshop) {
$entry->productPriceWebshop = $entry->productPriceRetail;
}
}
});- Create an entry within that section, enter a value into
productPriceRetailand save the entry - You'll see that
productPriceWebshopnow has a copy of that value on the site that it was being saved from, however this value is not applied to the other site. - If you now re-save the entry the value would be propegated.
Expected behavior
I expect the value of any non-translatable fields to be consistent across all of my sites. However since that is probably not how this works instead I'd like to have the ability to at least catch the $entry->firstSave and somehow manually propagate the changes?
Craft CMS version
5.8.16
PHP version
8.3.20
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
Reactions are currently unavailable