diff --git a/core/lib/Drupal/Core/Field/FieldConfigInterface.php b/core/lib/Drupal/Core/Field/FieldConfigInterface.php index 13ac848..f5a86a6 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigInterface.php +++ b/core/lib/Drupal/Core/Field/FieldConfigInterface.php @@ -178,7 +178,7 @@ public function addPropertyConstraints($name, array $constraints); * @code * // Add a constraint to the 'field_username' FieldItemList. * // e.g. $node->field_username - * $fields['field_username']->addConstraint('UniqueField', []); + * $fields['field_username']->addConstraint('UniqueField', ['message' => t('The username %value is already taken.')]); * @endcode * * If you wish to apply a constraint to a \Drupal\Core\Field\FieldItem instead diff --git a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php index c917cc9..da58934 100644 --- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php @@ -19,7 +19,7 @@ */ class UniqueFieldConstraint extends Constraint { - public $message = 'The @entity_type with the @field_name %value already exists.'; + public $message = 'A @entity_type with the @field_name %value already exists.'; /** * {@inheritdoc} diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index 40c19e9..ec57d5b 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -188,7 +188,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { 'weight' => -5, )) ->setDisplayConfigurable('form', TRUE) - ->addConstraint('UniqueField'); + ->addConstraint('UniqueField', ['message' => t('A block with description %value already exists.')]); $fields['type'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Block type')) diff --git a/core/modules/block_content/src/Tests/BlockContentCreationTest.php b/core/modules/block_content/src/Tests/BlockContentCreationTest.php index 66c259a..7afb177 100644 --- a/core/modules/block_content/src/Tests/BlockContentCreationTest.php +++ b/core/modules/block_content/src/Tests/BlockContentCreationTest.php @@ -66,7 +66,7 @@ public function testBlockContentCreation() { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('The custom block with the block description %value already exists.', array( + $this->assertRaw(format_string('A block with description %value already exists.', array( '%value' => $edit['info[0][value]'] ))); $this->assertResponse(200); @@ -124,7 +124,7 @@ public function testBlockContentCreationMultipleViewModes() { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('The custom block with the block description %value already exists.', array( + $this->assertRaw(format_string('A block with description %value already exists.', array( '%value' => $edit['info[0][value]'] ))); $this->assertResponse(200); diff --git a/core/modules/block_content/src/Tests/BlockContentValidationTest.php b/core/modules/block_content/src/Tests/BlockContentValidationTest.php index e13f010..85bf6e9 100644 --- a/core/modules/block_content/src/Tests/BlockContentValidationTest.php +++ b/core/modules/block_content/src/Tests/BlockContentValidationTest.php @@ -37,7 +37,7 @@ public function testValidation() { // Make sure the violation is on the info property $this->assertEqual($violations[0]->getPropertyPath(), 'info'); // Make sure the message is correct. - $this->assertEqual($violations[0]->getMessage(), format_string('The custom block with the block description %value already exists.', [ + $this->assertEqual($violations[0]->getMessage(), format_string('A block with description %value already exists.', [ '%value' => $block->label(), ])); } diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 2952bce..7e0b0de 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -465,7 +465,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { // No Length constraint here because the UserName constraint also covers // that. 'UserName' => array(), - 'UniqueField' => array(), + 'UniqueField' => array('message' => t('The username %value is already taken.')), )); $fields['pass'] = BaseFieldDefinition::create('password') @@ -477,7 +477,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Email')) ->setDescription(t('The email of this user.')) ->setDefaultValue('') - ->addConstraint('UniqueField') + ->addConstraint('UniqueField', ['message' => t('The email address %value is already taken.')]) ->addConstraint('UserMailRequired') ->addConstraint('ProtectedUserField'); diff --git a/core/modules/user/src/Tests/UserEditTest.php b/core/modules/user/src/Tests/UserEditTest.php index 8883381..46502f4 100644 --- a/core/modules/user/src/Tests/UserEditTest.php +++ b/core/modules/user/src/Tests/UserEditTest.php @@ -28,7 +28,7 @@ function testUserEdit() { // Test that error message appears when attempting to use a non-unique user name. $edit['name'] = $user2->getUsername(); $this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save')); - $this->assertRaw(t('The user with the name %name already exists.', array('%name' => $edit['name']))); + $this->assertRaw(t('The username %name is already taken.', array('%name' => $edit['name']))); // Check that filling out a single password field does not validate. $edit = array(); diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index e7ee6f3..ff3fa30 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -141,13 +141,13 @@ function testRegistrationEmailDuplicates() { // Attempt to create a new account using an existing email address. $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertText(t('The user with the email @email already exists.', array('@email' => $duplicate_user->getEmail())), 'Supplying an exact duplicate email address displays an error message'); + $this->assertText(t('The email address @email is already taken.', array('@email' => $duplicate_user->getEmail())), 'Supplying an exact duplicate email address displays an error message'); // Attempt to bypass duplicate email registration validation by adding spaces. $edit['mail'] = ' ' . $duplicate_user->getEmail() . ' '; $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertText(t('The user with the email @email already exists.', array('@email' => $duplicate_user->getEmail())), 'Supplying a duplicate email address with added whitespace displays an error message'); + $this->assertText(t('The email address @email is already taken.', array('@email' => $duplicate_user->getEmail())), 'Supplying a duplicate email address with added whitespace displays an error message'); } function testRegistrationDefaultValues() { diff --git a/core/modules/user/src/Tests/UserValidationTest.php b/core/modules/user/src/Tests/UserValidationTest.php index c6512f1..ec44a79 100644 --- a/core/modules/user/src/Tests/UserValidationTest.php +++ b/core/modules/user/src/Tests/UserValidationTest.php @@ -102,7 +102,7 @@ function testValidation() { $violations = $user->validate(); $this->assertEqual(count($violations), 1, 'Violation found on name collision.'); $this->assertEqual($violations[0]->getPropertyPath(), 'name'); - $this->assertEqual($violations[0]->getMessage(), t('The user with the name %name already exists.', array('%name' => 'existing'))); + $this->assertEqual($violations[0]->getMessage(), t('The username %name is already taken.', array('%name' => 'existing'))); // Make the name valid. $user->set('name', $this->randomMachineName()); @@ -131,7 +131,7 @@ function testValidation() { $violations = $user->validate(); $this->assertEqual(count($violations), 1, 'Violation found when email already exists.'); $this->assertEqual($violations[0]->getPropertyPath(), 'mail'); - $this->assertEqual($violations[0]->getMessage(), t('The user with the email %mail already exists.', array('%mail' => 'existing@example.com'))); + $this->assertEqual($violations[0]->getMessage(), t('The email address %mail is already taken.', array('%mail' => 'existing@example.com'))); $user->set('mail', NULL); $violations = $user->validate(); $this->assertEqual(count($violations), 1, 'E-mail addresses may not be removed');