Force value of field based on values of other fields on an entity

Back in Drupal 7, whether this was a good idea or not even then, it seems we always did munging of values before saving in the validation step. In Drupal 8 the Symfony constraint and constraint validator approach and i think it’s designed to not change values on an entity, but only enforce constraints when validating.

The right way to manipulate values on save in Drupal 8 is with hook_entity_presave or it’s slightly more specific colleague, hook_ENTITY_TYPE_presave.

Credit to:

For straight validating, the constraint stuff looks pretty cool, if a bit more complex: