Skip to content

Commit 3cfe971

Browse files
committed
code fixes for #1333 and #1229
1 parent c58d597 commit 3cfe971

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cookbook/validation/custom_constraint.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ the ``message`` and ``protocols`` properties:
2121
*/
2222
class Protocol extends Constraint
2323
{
24-
public $message = 'This value is not a valid protocol';
24+
public $message = 'The value "%protocol%" is not a valid protocol';
2525
public $protocols = array('http', 'https', 'ftp', 'ftps');
2626
}
2727
@@ -62,7 +62,7 @@ Furthering our example, take a look at the ``ProtocolValidator`` as an example:
6262
public function isValid($value, Constraint $constraint)
6363
{
6464
if (!in_array($value, $constraint->protocols)) {
65-
$this->setMessage($constraint->message, array('%protocols%' => $constraint->protocols));
65+
$this->setMessage($constraint->message, array('%protocol%' => $value));
6666
6767
return false;
6868
}
@@ -142,8 +142,9 @@ With this, the validator ``isValid()`` method gets an object as its first argume
142142
{
143143
if ($protocol->getFoo() != $protocol->getBar()) {
144144

145-
// bind error message on foo property
146-
$this->context->addViolationAtSubPath('foo', $constraint->getMessage(), array(), null);
145+
$propertyPath = $this->context->getPropertyPath() . 'foo';
146+
$this->context->setPropertyPath($propertyPath);
147+
$this->context->addViolation($constraint->getMessage(), array(), null);
147148

148149
return false;
149150
}

0 commit comments

Comments
 (0)