Change autocomplete results based users selected checkbox I have a drupal 8 site that uses the paragraphs module. In one of the paragraph is a field that contains an autocomplete field. It is already set up to reference a small list of Content Types.  For example, "News, Events, Product, Image" are four referenced for the autocomplete.  

On another paragraph, it includes this autocomplete but also has a field called "Select a Content Type", it lists out ALL the content types. This is used on the content type.  When someone adds a new content they are presented with a list of all the content types as a checkbox and the autocomplete field.  

My goal is to only display the selected results from the "select a content type" field onto the autocomplete field. 

So when a user selects a "news" / "events" / "Product" / "image" from the "Select a content type" field, the autocomplete only displays nodes of what was selected. If I select news then only news appears when I start entering data. If I select News and events, then both will show. If I select none then a custom message appears.

I have looked around and found how to overwrite getReferenceableEntities but I don't see a way to pass two variables: one from the checkbox field and the autocomplete entered value.

I suspect there will be JS involved to have the form send both checkbox and search value over but I don't know where to begin.
MYMODULE/src/EntityAutoCompleteMatcher.php:

class EntityAutocompleteMatcher extends \Drupal\Core\Entity\EntityAutocompleteMatcher {

  /**
   * Gets matched labels based on a given search string.
   */
  public function getMatches($target_type, $selection_handler, $selection_settings, $string = '') {

    $matches = [];

    $options = [
      'target_type'      =&gt; $target_type,
      'handler'          =&gt; $selection_handler,
      'handler_settings' =&gt; $selection_settings,
    ];

    $handler = $this-&gt;selectionManager-&gt;getInstance($options);

    if (isset($string)) {
      // Get an array of matching entities.
      $match_operator = !empty($selection_settings['match_operator']) ? $selection_settings['match_operator'] : 'CONTAINS';
      $entity_labels = $handler-&gt;getReferenceableEntities($string, $match_operator, 10);

      // Loop through the entities and convert them into autocomplete output.
      foreach ($entity_labels as $values) {
        foreach ($values as $entity_id =&gt; $label) {

          $entity = \Drupal::entityTypeManager()-&gt;getStorage($target_type)-&gt;load($entity_id);
          $entity = \Drupal::entityManager()-&gt;getTranslationFromContext($entity);

          // Only return bundle types we want.
          if ($entity-&gt;bundle() == 'page') {
            $matches[] = ['value' =&gt; $label, 'label' =&gt; $label];
          }
        }
      }
    }

    return $matches;
  }

}


More work would need to be done, but this shows where we can control the returned list of referenced entities.

See:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityAutocompleteMatcher.php/8.8.x