Entity reference view depending on other field I have a custom content type that contains an entity reference field (field_referencefield) and one more field as select box (field_triggerfield).

The values of field_referencefield should depend on the selection of field_triggerfield. This should happen in the create node form. I.e. If I change the selected item in field_triggerfield during node creation, different values for field_referencefield should be available. Maybe this can be achieved using views reference.
Step 1

On the field definition for the reference field that is dependent on another field you are going to change the reference method to views 



Step 2


You'll need to create a reference view for this data. 
Make sure to add a contextual field/relationships/etc on the reference view that takes the other value from your form that helps it pre-filter the autocomplete results.




Step 3

in a module or wherever hook into hook_form_alter and replace the reference field


/**
 * implements hook_form_alter
 *
 * @param array $form
 * @param array $form_state
 * @param string $form_id
 */
function my_module_form_alter(&amp;$form, $form_state, $form_id) {

  if (in_array($form_id, ['node_mycontenttype_form', 'node_mycontenttype_edit_form'])) {
    // Add a wrapper around the reference field.
    $form['field_referencefield']['#prefix'] = '&lt;div id="some-wrapper"&gt;';
    $form['field_referencefield']['#suffix'] = '&lt;/div&gt;';

    // Add an ajax callback that replaces the contents of the wrapper.
    $form['field_triggerfield']['widget'][0]['target_id']['#ajax'] = [
      'callback' =&gt; 'mymodule_field_mycontenttype_trigger',
      'wrapper' =&gt; 'some-wrapper',
      'event' =&gt; 'autcompletechange autocompleteclose',
      'progress' =&gt; [
        'type' =&gt; 'throbber',
        'message' =&gt; t('Fetching filtered content...'),
      ],
    ];

    $field_triggerfield_value = $form_state-&gt;getValue('field_triggerfield');
    if (!empty($field_triggerfield_value)) {
      $contextual_filter_value = $field_triggerfield_value[0]['target_id'];
      $form['field_referencefield']['widget'][0]['target_id']['#selection_settings']['view']['arguments'][0] = $contextual_filter_value;
    }
  }
}

function mymodule_field_mycontenttype_trigger(array $form, $form_state) {
  return $form['field_referencefield'];
}


so what this is doing (I've assumed node edit form and node add form for a content type):


putting a wrapper around the reference field whose available values should change
adding an ajax callback to the trigger field that should cause the reference field to filter (the contextual field)
when the trigger field changes


add a new contextual value to the view reference field's view from the trigger field
replace the contents of the wrapper field in the form