Problem/Motivation
The uid field on media entities is not set to required, but the database field is set to NOT NULL.
To reproduce:
- go to /media/add/image
- fill in the required form elements
- delete the contents of the Authored by form element
- save the form
The site crashes with a storage exception because the uid database field may not be NULL.
Steps to reproduce
Proposed resolution
Ideally, deal with #3260173: EntityOwnerTrait does not define the owner field as required, but the DB field is NOT NULL so it's fixed for all entities.
As an interim, copy the code from Node::preSave() to Media::preSave():
// If no owner has been set explicitly, make the anonymous user the owner.
if (!$translation->getOwner()) {
$translation->setOwnerId(0);
}
}