I have a node type "Kaboodle" and its image field is media entity reference field. I want to set default image fid in image field value if user has not uploaded any image on the field while saving node edit form or adding new node.
Please provide solution if anyone has or share your logic so that I can solve this.
Thanks
In a
hook_node_presave(NodeInterface $node)
, for the$node->bundle()
you want, if the value of your media field is empty set it to the media entity id you want (be careful this media entity id might be different between your dev and prod environments, you might need to load the media by title property in order to get its id). Just set the value for the field, it will be saved automatically when node_save wil be called.