I got a bit of help with this from Discord. Here is what I have:
Event::on(Entry::class, Element::EVENT_AFTER_SAVE, function (ModelEvent $e) {
$entry = $e->sender;
if ($entry->sectionId !== 7) {
return;
}
if ($entry->typeId !== 9) {
return;
}
$parent = $entry->getParent();
if (!$parent) {
return;
}
$parent->dateUpdated = $entry->dateUpdated;
Craft::$app->getElements()->saveElement($parent);
});
The trouble is that the if conditions aren't working; with the above code, the parent entry is not updated. As soon as I remove those two if statements, the code works and the parent is updated. However, I don't want to run this on all sections/structures.
Does anyone know what might be going wrong? I've checked the section/type IDs many times :)
Thanks in advance!