Problem/Motivation

If an entity reference field is managed by a view and configured in autocomplete mode, an incomplete sentence is displayed.

File: web/core/modules/media/src/Hook/MediaHooks.php L208-216.
if ($is_autocomplete) {
$elements['#media_help']['#media_list_help'] = $this->t('Type part of the media name.');
$overview_url = Url::fromRoute('entity.media.collection');
if ($overview_url->access()) {
$elements['#media_help']['#media_list_link'] = $this->t('See the <a href=":list_url" target="_blank">media list</a> (opens a new window) to help locate media.', [':list_url' => $overview_url->toString()]);
}
$bundle_labels = array_intersect_key(\Drupal::service('entity_type.bundle.info')->getBundleLabels('media'), $allowed_bundles);
$elements['#media_help']['#allowed_types_help'] = $this->t('Allowed media types: %types', ['%types' => implode(", ", $bundle_labels)]);
}

The $bundle_labels variable is empty because a view is used. You can see the following sentence:
"Enter part of the media name. Consult the list of media (opens a new window) to help locate the media. Allowed media types: "

Steps to reproduce the issue

  1. Install Drupal 11.4.1
  2. Create content type A
  3. Create content type B
  4. Create an "entity reference" view based on content type B
  5. Add an entity reference field to content type A
  6. Configure the field's handler to use a view and select the view in question
  7. In the form display section, configure this field to use autocomplete mode

Proposed resolution

Add a check for the handler method, or verify that $bundle_labels is not empty.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

nicoc created an issue. See original summary.

quietone’s picture

Version: 11.4.x-dev » main
Issue summary: View changes

Hi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.