diff --git a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php index 41358a5256..011fd986b7 100644 --- a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php @@ -323,23 +323,18 @@ protected static function matchEntityByTitle(SelectionInterface $handler, $input $params = [ '%value' => $input, '@value' => $input, + '@entities' => \Drupal::entityTypeManager()->getDefinition($element['#target_type'])->getPluralLabel(), ]; if (empty($entities)) { if ($strict) { // Error if there are no entities available for a required field. - $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)); - } + $form_state->setError($element, t('There are no @entities matching "%value".', $params)); } } elseif (count($entities) > 5) { $params['@id'] = key($entities); // Error if there are more than 5 matching entities. - $form_state->setError($element, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)".', $params)); + $form_state->setError($element, t('Many @entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)".', $params)); } elseif (count($entities) > 1) { // More helpful error if there are only a few matching entities. @@ -348,7 +343,7 @@ protected static function matchEntityByTitle(SelectionInterface $handler, $input $multiples[] = $name . ' (' . $id . ')'; } $params['@id'] = $id; - $form_state->setError($element, t('Multiple entities match this reference; "%multiple". Specify the one you want by appending the id in parentheses, like "@value (@id)".', ['%multiple' => strip_tags(implode('", "', $multiples))] + $params)); + $form_state->setError($element, t('Multiple @entities match this reference; "%multiple". Specify the one you want by appending the id in parentheses, like "@value (@id)".', ['%multiple' => strip_tags(implode('", "', $multiples))] + $params)); } else { // Take the one and only matching entity. diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php index d17d08d7c2..fc6c801ca6 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php @@ -172,7 +172,7 @@ public function testFieldAdminHandler() { $this->drupalPostForm('node/add/' . $this->type, $edit, t('Save')); // Assert that entity reference autocomplete field is validated. - $this->assertText(t('Invalid value "@value" chosen for "@field_name".', ['@value' => 'Test', '@field_name' => 'Test Entity Reference Field (value 1)'])); + $this->assertText(t('There are no content items matching "@entity"', ['@entity' => 'Test'])); $edit = [ 'title[0][value]' => 'Test', @@ -182,7 +182,7 @@ public function testFieldAdminHandler() { // Assert the results multiple times to avoid sorting problem of nodes with // the same title. - $this->assertText(t('Multiple entities match this reference;')); + $this->assertText(t('Multiple content items match this reference;')); $this->assertText(t("@node1", ['@node1' => $node1->getTitle() . ' (' . $node1->id() . ')'])); $this->assertText(t("@node2", ['@node2' => $node2->getTitle() . ' (' . $node2->id() . ')'])); $this->assertText(t('Specify the one you want by appending the id in parentheses, like "@example".', ['@example' => $node2->getTitle() . ' (' . $node2->id() . ')'])); diff --git a/core/modules/node/tests/src/Functional/NodeEditFormTest.php b/core/modules/node/tests/src/Functional/NodeEditFormTest.php index b7f345c769..ecc7d738a4 100644 --- a/core/modules/node/tests/src/Functional/NodeEditFormTest.php +++ b/core/modules/node/tests/src/Functional/NodeEditFormTest.php @@ -264,7 +264,7 @@ protected function checkVariousAuthoredByValues(NodeInterface $node, $form_eleme $form_element_name => 'invalid-name', ]; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); - $this->assertRaw(t('Invalid value "%name" chosen for "%field_name".', ['%name' => 'invalid-name', '%field_name' => 'authored by'])); + $this->assertRaw(t('There are no users matching "%name".', ['%name' => 'invalid-name'])); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). diff --git a/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php b/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php index b362416d5e..f030362914 100644 --- a/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php +++ b/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php @@ -106,7 +106,7 @@ public function testAdminUserInterface() { 'options[value]' => implode(', ', $users), ]; $this->drupalPostForm($path, $edit, t('Apply')); - $this->assertRaw(t('Invalid value "%value" chosen for "%field_name".', ['%value' => implode(', ', $users), '%field_name' => 'Usernames'])); + $this->assertRaw(t('There are no users matching "%value".', ['%value' => implode(', ', $users)])); // Pass in an invalid username and a valid username. $random_name = $this->randomMachineName(); @@ -117,7 +117,7 @@ public function testAdminUserInterface() { ]; $users = [$users[0]]; $this->drupalPostForm($path, $edit, t('Apply')); - $this->assertRaw(t('Invalid value "%value" chosen for "%field_name".', ['%value' => implode(', ', $users), '%field_name' => 'Usernames'])); + $this->assertRaw(t('There are no users matching "%value".', ['%value' => implode(', ', $users)])); // Pass in just valid usernames. $users = $this->names; @@ -126,7 +126,7 @@ public function testAdminUserInterface() { 'options[value]' => implode(', ', $users), ]; $this->drupalPostForm($path, $edit, t('Apply')); - $this->assertNoRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)])); + $this->assertNoRaw(t('There are no users matching "%value".', ['%value' => implode(', ', $users)])); } /** @@ -142,7 +142,7 @@ public function testExposedFilter() { $users = array_map('strtolower', $users); $options['query']['uid'] = implode(', ', $users); $this->drupalGet($path, $options); - $this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)])); + $this->assertRaw(t('There are no users matching "%value".', ['%value' => implode(', ', $users)])); // Pass in an invalid target_id in for the entity_autocomplete value format. // There should be no errors, but all results should be returned as the @@ -162,7 +162,7 @@ public function testExposedFilter() { $users = [$users[0]]; $this->drupalGet($path, $options); - $this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)])); + $this->assertRaw(t('There are no users matching "%value".', ['%value' => implode(', ', $users)])); // Pass in just valid usernames. $users = $this->names; diff --git a/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php b/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php index 1639a301b5..0ccdb6c1a8 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php @@ -279,7 +279,7 @@ public function testInvalidEntityAutocompleteElement() { ]); $form_builder->submitForm($this, $form_state); $this->assertCount(1, $form_state->getErrors()); - $this->assertEqual($form_state->getErrors()['single'], t('There are no entities matching "%value".', ['%value' => 'single - non-existent label'])); + $this->assertEqual($form_state->getErrors()['single'], t('There are no test entity entities matching "%value".', ['%value' => 'single - non-existent label'])); // Test 'single' with a entity ID that doesn't exist. $form_state = (new FormState()) @@ -302,7 +302,7 @@ public function testInvalidEntityAutocompleteElement() { // The element without 'autocreate' support still has to emit a warning when // the input doesn't end with an entity ID enclosed in parentheses. $this->assertCount(1, $form_state->getErrors()); - $this->assertEqual($form_state->getErrors()['single_no_validate'], t('There are no entities matching "%value".', ['%value' => 'single - non-existent label'])); + $this->assertEqual($form_state->getErrors()['single_no_validate'], t('There are no test entity entities matching "%value".', ['%value' => 'single - non-existent label'])); $form_state = (new FormState()) ->setValues([