[Form] added support for error message pluralization
This commit is contained in:
parent
345981f6b6
commit
7a6376eb29
@ -61,7 +61,8 @@ class DelegatingValidator implements FormValidatorInterface
|
|||||||
$propertyPath = new PropertyPath($violation->getPropertyPath());
|
$propertyPath = new PropertyPath($violation->getPropertyPath());
|
||||||
$template = $violation->getMessageTemplate();
|
$template = $violation->getMessageTemplate();
|
||||||
$parameters = $violation->getMessageParameters();
|
$parameters = $violation->getMessageParameters();
|
||||||
$error = new FormError($template, $parameters);
|
$pluralization = $violation->getMessagePluralization();
|
||||||
|
$error = new FormError($template, $parameters, $pluralization);
|
||||||
|
|
||||||
$child = $form;
|
$child = $form;
|
||||||
foreach ($propertyPath->getElements() as $element) {
|
foreach ($propertyPath->getElements() as $element) {
|
||||||
@ -82,7 +83,8 @@ class DelegatingValidator implements FormValidatorInterface
|
|||||||
$propertyPath = $violation->getPropertyPath();
|
$propertyPath = $violation->getPropertyPath();
|
||||||
$template = $violation->getMessageTemplate();
|
$template = $violation->getMessageTemplate();
|
||||||
$parameters = $violation->getMessageParameters();
|
$parameters = $violation->getMessageParameters();
|
||||||
$error = new FormError($template, $parameters);
|
$pluralization = $violation->getMessagePluralization();
|
||||||
|
$error = new FormError($template, $parameters, $pluralization);
|
||||||
|
|
||||||
foreach ($mapping as $mappedPath => $child) {
|
foreach ($mapping as $mappedPath => $child) {
|
||||||
if (preg_match($mappedPath, $propertyPath)) {
|
if (preg_match($mappedPath, $propertyPath)) {
|
||||||
|
@ -30,6 +30,12 @@ class FormError
|
|||||||
*/
|
*/
|
||||||
protected $messageParameters;
|
protected $messageParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value for error message pluralization
|
||||||
|
* @var integer|null
|
||||||
|
*/
|
||||||
|
protected $messagePluralization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -37,14 +43,16 @@ class FormError
|
|||||||
* $messageTemplate.
|
* $messageTemplate.
|
||||||
* @see Symfony\Component\Translation\Translator
|
* @see Symfony\Component\Translation\Translator
|
||||||
*
|
*
|
||||||
* @param string $messageTemplate The template for the error message
|
* @param string $messageTemplate The template for the error message
|
||||||
* @param array $messageParameters The parameters that should be
|
* @param array $messageParameters The parameters that should be
|
||||||
* substituted in the message template.
|
* 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->messageTemplate = $messageTemplate;
|
||||||
$this->messageParameters = $messageParameters;
|
$this->messageParameters = $messageParameters;
|
||||||
|
$this->messagePluralization = $messagePluralization;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,4 +84,14 @@ class FormError
|
|||||||
{
|
{
|
||||||
return $this->messageParameters;
|
return $this->messageParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value for error message pluralization.
|
||||||
|
*
|
||||||
|
* @return integer|null
|
||||||
|
*/
|
||||||
|
public function getMessagePluralization()
|
||||||
|
{
|
||||||
|
return $this->messagePluralization;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user