Set entity reference field in form to readonly I am building a custom module to set default values for entity reference fields. To avoid overwriting these defaults, i would like to set the field readonly. While I got the defaults to work, setting it readonly does not work, the field is still editable. Here is my code :

function prepopulate_references_form_alter(&amp;$form, $form_state, $form_id) {
  $query = new EntityFieldQuery();
  $query
    -&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'producttype')
  $result = $query-&gt;execute();
  $refobject_ids = array_keys($result['node']);
  // the next line works great:
  $form['field_testreference'][LANGUAGE_NONE]['#default_value'] = $refobject_ids;
  // this line doesn't have any effect:
  $form['field_testreference'][LANGUAGE_NONE]['#attributes']['readonly'] = TRUE;
  // ... and this one neither:
  $form['field_testreference'][LANGUAGE_NONE]['#attributes']['disabled'] = TRUE;


What is the problem here?

Edited:
As Darvanen suggested, dpm() shows that $form['field_testreference']['#access'] = FALSE; works great.
Perhaps it's because you're referencing a language where it isn't necessary, try one of these:

$form['field_testreference']['#access'] = FALSE;


or

$form['field_testreference']['#attributes']['readonly'] = TRUE;