I am trying to change the format that it shows by default in the text fields that have an associated reference entity.

I found an article where a format modification is made, I think it may be a good starting point, but this module changes the format of all the fields of the whole site, what I am trying to do is that I can define the format by type of content, that is, for Articles, it would have one format and another type of content, depending on what is most convenient.

For example, in the module mentioned, it changes the behavior of the autocomplete globally, is there a way to do it by type of content?

namespace Drupal\alter_entity_autocomplete\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;

use Symfony\Component\Routing\RouteCollection;

class AutocompleteRouteSubscriber extends RouteSubscriberBase {
  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('system.entity_autocomplete')) {
      $route->setDefault('_controller', '\Drupal\alter_entity_autocomplete\Controller\EntityAutocompleteController::handleAutocomplete');

Is there any way to do it?

The github project of the module

1 Answer 1


You can filter for the entity type & bundle in the getMatches() method.

It is also possible to add specific handlers to your forms: https://www.qed42.com/blog/autocomplete-drupal-8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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