How to use entity autocomplete for "user" target_type with specific roles? I have created a form field with user autocomplete as below.

$form['user_list'] = [
      '#title' =&gt; ('Select User'),
      '#type' =&gt; 'entity_autocomplete',
      '#target_type' =&gt; 'user',
      '#required' =&gt; TRUE,
      '#selection_settings' =&gt; [
        'include_anonymous' =&gt; FALSE,
        'roles' =&gt; ['sales'],
      ],
    ];


I used "#selection_settings" with roles specific, but this is not working.
I want to filter user with "sales" only.
The selection settings array is passed to the plugin options,
 which in this case is Drupal\user\Plugin\EntityReferenceSelection\UserSelection.

In that class, you can see that the relevant array key is $options['filter']['role'], which is an array. 

Therefore, the correct code here is:

$form['user_list'] = [
  '#title' =&gt; ('Select User'),
  '#type' =&gt; 'entity_autocomplete',
  '#target_type' =&gt; 'user',
  '#required' =&gt; TRUE,
  '#selection_settings' =&gt; [
    'include_anonymous' =&gt; FALSE,
    'filter' =&gt; [
      'role' =&gt; ['sales'],
    ],
  ],
];