How to change the view for a "Views: Filter by an entity reference view"-mode entity reference field on the node/add or edit form? I have 2 content types: registration (R) and class (C). R has an entity reference field which is referencing to C using the "Views: Filter by an entity reference view" mode. The entity reference field must use the select list widget. User account also has an entity reference field field_default_class which is referencing to C. Because of business logic, the field_default_class's value never exists in the entity reference view's filtered result which is used in the R node.

Now if an authenticated user adds or edits a node of R, I need to check if current user's field_default_class is set or not. If set, I need to pragmatically set the R's entity reference nodes' select list to the user's field_default_class's value, then disable the select list for disallowing user to change the value.

I guess it's difficult to set a select list's option value which is not in the view's filtered results. Or maybe my codes as below have errors. But I don't know where is wrong :-(

/**
 * Implements hook_form_alter().
 */
function sisucustom_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'registration_node_form') {
    global $user;
    $account = user_load($user-&gt;uid);
    if (isset($account-&gt;field_default_class['und'][0]['target_id'])) {
      $entity_node = node_load($account-&gt;field_default_class['und'][0]['target_id']);
      $options = array($entity_node-&gt;nid =&gt; $entity_node-&gt;title);
      $form['field_register_for_class'][LANGUAGE_NONE][0]['target_id']['#options'] = $options;
      $form['field_register_for_class'][LANGUAGE_NONE][0]['target_id']['#default_value'] = $entity_node-&gt;nid;
      $form['field_register_for_class']['LANGUAGE_NONE']['#attributes']['#disabled'] = TRUE;
    }
  }
}


Or, is it possible to change the associated view to the entity reference field in node R? Because I can create another entity reference view which filters out only the one C which equals the current user's field_default_class's value. If it is, how to do it (in which hook)?

PS: I heavily use conditional fields module in node R. So maybe there are some pits against my goal. How to avoid those?
My code is wrong, now it works as below:

/**
 * Implements hook_form_alter().
 */
function sisucustom_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'registration_node_form') {
    global $user;
    $account = user_load($user-&gt;uid);
    if (isset($account-&gt;field_default_class['und'][0]['target_id'])) {
      $entity_node = node_load($account-&gt;field_default_class['und'][0]['target_id']);
      $options = array($entity_node-&gt;nid =&gt; $entity_node-&gt;title);
      $form['field_register_for_class'] = array(
        '#type' =&gt; 'select',
        '#options' =&gt; $options,
      );
    }
  }
}


Finally I searched out a thread answering my question about modifying the widget info here.