Change of error validation message

Created the entity browser field with cardinality as 1 and in the the form if we tries to select multiple file throwing validation error as

You can not select more than 1 entities. which should be

'You can not select more than 1 entity

Comments

N.kishorekumar created an issue. See original summary.

slashrsm’s picture

Issue tags: +D8Media, +Novice

This is very suitable for someone less experienced contributors.

bhavesh.rohida’s picture

Assigned: Unassigned » bhavesh.rohida
n.kishorekumar’s picture

StatusFileSize
new1.1 KB
n.kishorekumar’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: entity_browser-2795671-4.patch, failed testing.

The last submitted patch, 4: entity_browser-2795671-4.patch, failed testing.

n.kishorekumar’s picture

Version: 8.x-1.0-alpha7 » 8.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.17 KB

Please find the latest patch...

slashrsm’s picture

Status: Needs review » Needs work

Thank you for the patch!

-    if ($max !== EntityBrowserElement::CARDINALITY_UNLIMITED && $count > $max) {
+    //If the carinality value is 1 displaying the error message in singular
+    if ($max !== EntityBrowserElement::CARDINALITY_UNLIMITED && $count > $max && $max == 1) {
+      $message = 'You can not select more than %max entity.';
+    }
+    elseif ($max !== EntityBrowserElement::CARDINALITY_UNLIMITED && $count > $max) {
       $message = 'You can not select more than %max entities.';
+    }
+    if (isset($message)) {
       $parameters = ['%max' => $max];
       $violation = new ConstraintViolation($this->t($message, $parameters), $message, $parameters, $count, '', $count);

$this->formatPlural() should be used instead of $this->t(). This is standard way of handling translations of strings that require singular and plural form.

n.kishorekumar’s picture

Status: Needs work » Needs review
StatusFileSize
new1003 bytes

@slashrsm,
Thanks for the suggestion $this->formatPlural().

Changes done. Please review

slashrsm’s picture

Status: Needs review » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.