Change entity reference field widget type based on role? EDIT: See the original post below for context. I think I've figured out how to target the field's widget, and to do this based on the admin role, but the module doesn't seem to be recognizing the widget type for some reason. The reason I say this is that when the module is enabled, the targeted field disappears in the node edit form. I figure this means it's getting targeted correctly, but can't define how to display itself. I think this might be because the autocomplete widget is defined by the Entity Reference module itself, and not by Core. Do I have to tell the module where to find this widget type? Or is there another reason that this might be happening?

&lt;?php

//Assign role that will be affected by the module
if(user_access('administer')) {
  function entityreference_widget_field_widget_properties_alter(&amp;$widget, $context) {
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' &amp;&amp; $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
    }
  }
}


ORIGINAL POST: I have an entity reference field that I'm using in a "Review" content type. When users create a "Review", they are given options for this field in a select list based on Bands (another content type) that they have created. If a submitted review needs to be moderated, then an admin must go in and edit the "Review". When the review is edited by an admin, I need the band field to stay the same as it was when originally submitted. However, because of the nature of the how the options for the field are populated, the only options that appear when editing as an admin are "Bands" created by the admin user. 

There is a second widget type that can be chosen for the entity reference field, which is autocomplete. Is there a way that I can change the widget type from "select list" to "autocomplete" only when the content is being edited by an administrator? This way, users still have the select list for their bands, and administrators are not limited to only their bands. Otherwise, is there a way to that I can leave this specific field unaltered when editing the content?
I ended up getting this to work after finding hook_field_widget_properties_alter. This allows you to, as the hook implies, target the various properties of the widget directly. Global $user seems to provide the $user variable, which allows you to select the role that you want to apply the module to. You can change it from 'administrator' to 'authenticated user', 'anonymous user', or any other needed role to fit your needs.

&lt;?php
function entityreference_widget_field_widget_properties_alter(&amp;$widget, $context) {
  //Assign role that will be affected by the module
  global $user;

  if (in_array('administrator', $user-&gt;roles)) { 
    // Change entityreference widget 
    $field = $context['field'];
    if ($context['entity_type'] == 'node' &amp;&amp; $field['field_name'] == 'field_review_band') {
      $widget['type'] = 'entityreference_autocomplete';
      $widget['module'] = 'entityreference';
      $widget['settings']['match_operator'] = 'CONTAINS';
      $widget['settings']['size'] = '60';
    }
  }
}


To find out exactly which pieces of the widget needed to be altered, and what to, I created another test field of the type that I wanted to alter my current field to. I then inserted dsm($widget) within the hooks curly brackets of the hook, and then inspected the page with the field on it. 

Explanation of dsm() and dpm() for anybody who needs it:

There's so little help anywhere on how to use dsm() or dpm(), and working through this module finally made me understand it. Basically, modules target different elements, and in order to figure out what to target, or what you will be altering, you need to inspect the elements. What dsm() lets you do is view the properties of any given variable (e.g. $form_id most commonly it seems, or in this case $widget or $context) in each of the elements on the page that include it. If anybody stumbles on this and still needs clarification, feel free to ask. It took me forever to figure out how the heck to use dsm().