1

I have a custom form with the following autocomplete entity element.

$form['my_element'] = array(
  '#type' => 'entity_autocomplete',
  '#placeholder'=>'Search',
  '#target_type' => 'node',
  '#selection_settings' => [
    'target_bundles' => array('products'),
  ],
);

That form element autocompletes published and unpublished nodes, though.

Is there any way to prevent this from happening?

13
  • Normally unpublished nodes are filtered. But this depends on the user permissions. You probably are testing this logged in as admin.
    – 4uk4
    May 4, 2017 at 11:57
  • 1
    I've tested it offline and it does not filter unpublished
    – Fen Dev
    May 4, 2017 at 12:08
  • I've put your form element in one of my forms, only changed the target_bundle to article, and it works, when I'm logged in in as admin I get all articles, when I'm logged out only the published ones.
    – 4uk4
    May 4, 2017 at 12:20
  • Yes, but being disconnected from admin you also receive them, they appear in the dropdown
    – Fen Dev
    May 4, 2017 at 12:36
  • 1
    Are you sure your anon or authenticated users do not have the bypass node access permission? This definitely works correctly, most likely a configuration issue on your site
    – Berdir
    May 4, 2017 at 19:36

0

Browse other questions tagged or ask your own question.