How do I prevent an entity to be saved on update depending on conditions? I use content moderation, recently present in drupal 8 core, for editorial workflow.

I'd like to prevent the entity from being saved in an update if the current user is the author of the document.

how could I achieve that ?

this does a redirection but the entity saves still does happen

 function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {

 if ($entity-&gt;getEntityTypeId() !== 'content_moderation_state' ) {
    return;
}

$article_id=$entity-&gt;get('content_entity_id')-&gt;getString();
$article = \Drupal\node\Entity\Node::load($article_id);
 if($article-&gt;bundle()=='article') {

    $author_name=$article-&gt;getOwner()-&gt;getAccountName();
    $current_user_name=\Drupal::currentUser()-&gt;getAccountName();

    $moderation_state = $entity-&gt;get('moderation_state')-&gt;getString();

    switch ($moderation_state) {
        case 'peer-reviewing':

           $author=$article-&gt;getOwner();
           $current_user=\Drupal::currentUser();

            //$entity= $entity-&gt;original;
             //if author same as current user:
            drupal_set_message(t('original author cannot be reviewer.'), 'error');
            $url = $base_url.\Drupal::service('path.current')-&gt;getPath();
            $response = new Symfony\Component\HttpFoundation\RedirectResponse($url);
            $response-&gt;send();
            return;

 }
Could you not instead implement a hook_form_alter and do your condition checks, and hide/remove the submit button if it is the same user trying to review?

You could set the same message at the top of the form and not have to do any redirects.