Skip to content

Commit adb6229

Browse files
committed
Improve validation error wording
Resolves #9960
1 parent 3d6228b commit adb6229

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Administration
44
- Assets and Categries fields no longer have “Show the site menu” settings. ([#17156](https://github.com/craftcms/cms/issues/17156))
5+
- Improved the wording of validation errors caused by relational fields’ “Validate related [type]” settings. ([#9960](https://github.com/craftcms/cms/discussions/9960))
56

67
### Extensibility
78
- Added `craft\fields\BaseRelationField::canShowSiteMenu()`.

src/fields/BaseRelationField.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,13 @@ public function validateRelatedElements(ElementInterface $element): void
537537
}
538538

539539
if ($errorCount) {
540-
$elementType = static::elementType();
541-
$element->addError($this->handle, Craft::t('app', 'Validation errors found in {attribute} {type}; please fix them.', [
542-
'type' => $errorCount === 1 ? $elementType::lowerDisplayName() : $elementType::pluralLowerDisplayName(),
543-
'attribute' => Craft::t('site', $this->name),
540+
$selectedCount = (int)$value->count();
541+
$element->addError($this->handle, Craft::t('app', 'The selected {relatedType} {count, plural, =1{contains} other{contain}} validation errors, preventing this {type} from being saved. Edit the {relatedType} to fix them.', [
542+
'relatedType' => $selectedCount === 1
543+
? static::elementType()::lowerDisplayName()
544+
: static::elementType()::pluralLowerDisplayName(),
545+
'count' => $selectedCount,
546+
'type' => $element::lowerDisplayName(),
544547
]));
545548
}
546549
}

src/translations/en/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,7 @@
15141514
'The primary site will be loaded by default on the front end.' => 'The primary site will be loaded by default on the front end.',
15151515
'The request could not be understood by the server due to malformed syntax.' => 'The request could not be understood by the server due to malformed syntax.',
15161516
'The requested URL was not found on this server.' => 'The requested URL was not found on this server.',
1517+
'The selected {relatedType} {count, plural, =1{contains} other{contain}} validation errors, preventing this {type} from being saved. Edit the {relatedType} to fix them.' => 'The selected {relatedType} {count, plural, =1{contains} other{contain}} validation errors, preventing this {type} from being saved. Edit the {relatedType} to fix them.',
15171518
'The server doesn’t meet Craft’s new requirements:' => 'The server doesn’t meet Craft’s new requirements:',
15181519
'The table name prefix' => 'The table name prefix',
15191520
'The template Craft CMS will use for HTML emails' => 'The template Craft CMS will use for HTML emails',
@@ -1728,7 +1729,6 @@
17281729
'Validate custom fields on public registration' => 'Validate custom fields on public registration',
17291730
'Validate related {type}' => 'Validate related {type}',
17301731
'Validation errors for site: “{siteName}“' => 'Validation errors for site: “{siteName}“',
1731-
'Validation errors found in {attribute} {type}; please fix them.' => 'Validation errors found in {attribute} {type}; please fix them.',
17321732
'Value prefixed by “{prefix}”.' => 'Value prefixed by “{prefix}”.',
17331733
'Value suffixed by “{suffix}”.' => 'Value suffixed by “{suffix}”.',
17341734
'Value' => 'Value',

0 commit comments

Comments
 (0)