Alter field settings using hook? EDIT: I need to alter the settings of an entity reference field for administrators only. I need to change from the settings in the first image, to the settings in the second image.

 

The reasoning is that normally when creating content, I want users to select from the options available in the view. The options in the view are the "Bands" (a content type) that each individual user has created. However, if an admin needs to moderate the content, they are not allowed to save it after editing because the content of the field is not an option available to the admin (i.e. the band entered by the original user, and currently saved to the entity reference field, is not a band created by the admin and is therefore not an option in the admin's array). On save by an admin, it fails to save and throws an error of "The referenced entity (node: XXX) is invalid", staying on the edit page.

I tried changing $form_state through hook_form_alter, but apparently $form_state settings aren't saved on submission. So, I tried adding the alters to a validation function, which also didn't work for me. Then, I found the settings within $context of hook_field_widget_properties_alter, but it seems that $context can only be referenced and not altered. I also came across this post, which seems to state that there isn't really a hook for altering field settings.

Unfortunately, I have realized that I really need this feature in order to moderate my site. As always, any help is incredibly appreciated, as this issue seems to be beyond my abilities.

Here's some screenshots as requested by Minty:

Casual user's options, populated by the view, include only their own bands


What I want in the admin's options, which should be all the bands authored by all users. (note that it currently shows all bands, because I figured out how to do contextual filter in the view based on the current user, not because I was able to alter the field settings as asked by the issue):


Without the above fix, only the admin's bands appear in the list when editing a node. Therefore, as stated in the issue, it throws an error that the previously saved band is not a valid option for the field, and the node cannot be saved.
With respect to your original post, I ran into this exact issue here in drupalsixlandia and resolved it with a dull ax inside of views.  By exact meaning I wanted to have a select list of bands created by a user presented to them when they wanted to add an album, but when an admin went in to add/edit things, s/he should see all of the bands on the system.

So, I created a view and used this view to populate the band Node Reference field in the album type in CCK.  

I called it my_band and it filters on published bands and returns the Node Title of the band as the field. It has one argument, or in D7 a contextual filter, User Uid and in action to take if argument not present I provide a default argument via PHP code:

global $user;

if (in_array('super user', array_values($user-&gt;roles))) {
  return -1;
} else {
  return $user-&gt;uid;
}


Then in the Validation of that argument, I again use PHP:

if ($argument == -1) {
  return FALSE;
} else {
  return TRUE;
}


with display all values if validation fails.

So, now what happens (here at least) is if a casual user wants to create an album, s/he is presented with a list of only the bands s/he has created.  But, if any user with the super user role wants to create or edit an album, the validation is forced to fail, and the argument is ignored and all bands in the system are returned.

Perhaps with some D7ing of the code above this might work for you.