I want to do some server side checks to see if the entry should be saved or not.
In my plugin I have something like that
Event::on(
Elements::class,
Elements::EVENT_BEFORE_SAVE_ELEMENT,
function(ElementEvent $event) {
if ($event->element instanceof \craft\elements\Entry) {
$entry = $event->element;
if ( $entry->sectionId == 5 ) {
$entry->enabled = 0;
}
}
});
This works but what I want is for the entry to not be saved rather then be disabled. Something I could achive on the user model with:
$event->isValid = false;
Is there a way to withhold the entry from saving? The only other solution I can think if is to make the tests in the AFTER event and delete it if not passing the condition.