I've done quite a bit of research and trial and error configuration on this, but I can't figure it out and I can't shake the feeling that I must be missing something.

I'm trying to set the default (and only available) value of an entityreference field to the logged in user creating the node. I've set up an entity reference list views with a contextual filter of user: uid that provides the default of the currently logged in user and set that to be the view used by the entityreference field. I've made the field required and when new content is created, I get a select list with that one user in the list, but the actual value is set to 'select a value' rather than the single user that appears in the select list.

Surely this has to be a common use case and I must have missed something somewhere. Back in the userreference days I used php and global $user, but php is no longer an option for default values (even with cck for d7 installed).

what am I missing?


Title:setting default value for use reference to logged in user?setting default value for user reference to logged in user?

fixed typo

Views is so powerful at generating and sorting the list of values that a nice solution to this could be a checkbox that makes the default value the first (or last) item on the list.

It is the theme_options_none function from the Options module of the Field module in core that adds '- Select a value -'. It looks like the function entityreference_field_widget_form in the entityreference.module might be the place to make changes. I am very new to Drupal so I can't quite see how it works.

I have used a hook_form_alter() in a custom module to make a solution for the site I am working on.

There seems to be a strange inconsistency in the what entity reference fields require as a default. In one case, the default required was a string of the nid and in the other it required an array(0 => string_of_the nid). I can't understand why there is a difference looking at the two content types.