0

Does anyone know how to limit the autocomplete suggestions of Link Fields to only certain bundles -- not globally, but per Link Field instance? I nearly found a solution in customizing https://github.com/minnur/Alter-Entity-Autocomplete , but this is global for all autocompletes, and I need to get the calling Link Field instance somehow.

1

You can now use the following contributed module to solve the issue:

Link Field Autocomplete Filter

This module adds a Link Field configuration for filtering the allowed content types in the autocomplete field.

0

This is possible with hook form alter:

function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  // if $form_id ==  'xyz'
  $form['field_mylink']['widget'][0]['uri']['#selection_handler']="default:node";
  $form['field_mylink']['widget'][0]['uri']['#selection_settings']=[
    'target_bundles'=>['article'=>'article', 'page'=>'page'], //etc
  ];

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.