From 7a6376eb297fb91aebffd53ea6f4b9248c5b79cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 2 Feb 2012 13:36:42 +0100 Subject: [PATCH] [Form] added support for error message pluralization --- .../Validator/DelegatingValidator.php | 6 +++-- src/Symfony/Component/Form/FormError.php | 26 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php b/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php index 8717eb20b3..e3832fe143 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php @@ -61,7 +61,8 @@ class DelegatingValidator implements FormValidatorInterface $propertyPath = new PropertyPath($violation->getPropertyPath()); $template = $violation->getMessageTemplate(); $parameters = $violation->getMessageParameters(); - $error = new FormError($template, $parameters); + $pluralization = $violation->getMessagePluralization(); + $error = new FormError($template, $parameters, $pluralization); $child = $form; foreach ($propertyPath->getElements() as $element) { @@ -82,7 +83,8 @@ class DelegatingValidator implements FormValidatorInterface $propertyPath = $violation->getPropertyPath(); $template = $violation->getMessageTemplate(); $parameters = $violation->getMessageParameters(); - $error = new FormError($template, $parameters); + $pluralization = $violation->getMessagePluralization(); + $error = new FormError($template, $parameters, $pluralization); foreach ($mapping as $mappedPath => $child) { if (preg_match($mappedPath, $propertyPath)) { diff --git a/src/Symfony/Component/Form/FormError.php b/src/Symfony/Component/Form/FormError.php index 3a389cfd9b..bac75b5c51 100644 --- a/src/Symfony/Component/Form/FormError.php +++ b/src/Symfony/Component/Form/FormError.php @@ -30,6 +30,12 @@ class FormError */ protected $messageParameters; + /** + * The value for error message pluralization + * @var integer|null + */ + protected $messagePluralization; + /** * Constructor * @@ -37,14 +43,16 @@ class FormError * $messageTemplate. * @see Symfony\Component\Translation\Translator * - * @param string $messageTemplate The template for the error message - * @param array $messageParameters The parameters that should be - * substituted in the message template. + * @param string $messageTemplate The template for the error message + * @param array $messageParameters The parameters that should be + * substituted in the message template. + * @param integer $messagePluralization The value for error message pluralization */ - public function __construct($messageTemplate, array $messageParameters = array()) + public function __construct($messageTemplate, array $messageParameters = array(), $messagePluralization = null) { $this->messageTemplate = $messageTemplate; $this->messageParameters = $messageParameters; + $this->messagePluralization = $messagePluralization; } /** @@ -76,4 +84,14 @@ class FormError { return $this->messageParameters; } + + /** + * Returns the value for error message pluralization. + * + * @return integer|null + */ + public function getMessagePluralization() + { + return $this->messagePluralization; + } }