diff --git a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php index 7ac90b4781..2bb018edf7 100644 --- a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php @@ -327,8 +327,9 @@ protected static function matchEntityByTitle(SelectionInterface $handler, $input if (empty($entities)) { if ($strict) { // Error if there are no entities available for a required field. - if(isset($element['#title'])){ - $form_state->setError($element, t('Invalid value "%value" chosen for "%field_name".', $params + ['%field_name' => $element['#title']])); + $entity_type_label = \Drupal::entityTypeManager()->getDefinition($element['#target_type'])->getPluralLabel(); + if (isset($entity_type_label)) { + $form_state->setError($element, t('Invalid value "%value" chosen for "%field_name".', $params + ['%field_name' => $entity_type_label])); } else{ $form_state->setError($element, t('There are no entities matching "%value".', $params));