Score:0

How to set the default value for media entity in content type in a user friedly way?

in flag

In a new content type (Drupal 9) I have an Entity Reference field for Media (Image). I already chose and saved a default media entity in the field settings.

Unfortunately when creating a new node of this content type a user needs to remove the default media entity first before being able to upload his/her image. Since this seems not very user friedly I wonder whether there is a way to avoid this.

For example in a field that is an Entity Reference for Image (not Media) a set default image appears only if the user does not upload an own image. Here the user does not have to first remove the default image. I am looking for a way to accomplish this for the Entity Reference field for Media, but I can't find anything.

Any ideas?

ru flag
The media field is working as intended, it is actually the image field that is misbehaving: All entity reference fields store the default value in the database (which makes it null-able and exposable to e.g. JSON API), only the image field computes a fallback value. The behavior you describe in the admin UI is a side-effect of that bug, so I don't think there is any setting or module to "force the media field to be buggy".
Chris Happy avatar
cg flag
Hmm, I think you would have to implement this behaviour yourself. You could allow users to provide no value and in `hook_node_presave()`, add the value if the field is empty.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.