Is it possible to populate a field entity reference with query parameters? I created an entity reference field for a node filtered by a view type "entity reference", but I need to pass an argument in the contextual filter of this view, to filter entities on my field.

I tried passing my argument on the URL in a query parameter (e.g. node/add/page_interieur?dossier=2), but I never get results in my field autocomplete.

Is it possible to do that with this method or another one?

Settings for the contextual filter with the Query parameter option


  


Settings for the Entity reference field
To programmatically pass argument to my field entity reference with link node/add/page_interieur?dossier=512 :

use Drupal\node\Entity\Node;
use Drupal\Core\Form\FormStateInterface;

function my_module_form_alter(&amp;$form, FormStateInterface $form_state, $form_id){

  if ($form_id == 'node_page_interieur_form') {
    $nid  = \Drupal::request()-&gt;query-&gt;get('dossier');

    if (is_numeric($nid) &amp;&amp; isset($form['field_dossier_reference'])) {
      //autocomplete select field reference
      $form['field_dossier_reference']['widget']['#default_value'] = $nid;
      //disable field
      $form['field_dossier_reference']['#disabled'] = TRUE;
      //pass my ID like argument in my field to filter only pages referenced
      $form['field_liste_ref_dossier']['widget']['target_id']['#selection_settings']['view']['arguments'][] = $nid;
    }

    foreach (array_keys($form['actions']) as $action) {
      if ($action != 'preview' &amp;&amp; isset($form['actions'][$action]['#type']) &amp;&amp; $form['actions'][$action]['#type'] === 'submit') {
        $form['actions'][$action]['#submit'][] = 'science_po_page_interieur_form_submit';
      }
    }
  }
}


My contextual filter configuration in views :