Whats the correct way to programmatically include unpublished content in entity reference fields? (without views) I have a node reference field whose options get reduced to those nodes in which the current user is referenced:

function mymodule_process_form_field_project_ref(&amp;$field) {
  $field['#required'] = true;
  $field['widget']['#required'] = true;
  $options = $field['widget']['#options'];

  $project_nids = mymodule_user_get_referenced_projects();

  foreach ($options as $key =&gt; $label) {
    if (is_numeric($key)) {
      if (!in_array($key, $project_nids)) {
        unset($options[$key]);
      }
    }
  }

  $field['widget']['#options'] = $options;

}


The problem is, in $field['widget']['#options'] unpublished nodes are being removed in the first place. How to keep those? Do I have to define an own ServiceProviderBase class using the alter function?
You will need to create a custom EntityReferenceSelection plugin. 
Which should probably extend the NodeSelection plugin in core.