0

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?

2
  • 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".
    – Hudri
    Oct 26, 2022 at 13:58
  • 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. Oct 27, 2022 at 4:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.