Skip to content

Step 7 - Add basic validation

To provide basic validation that ensures both coordinates are provided, add assertions to the src/FieldType/Point2D/Value.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
use Symfony\Component\Validator\Constraints as Assert;

final class Value implements ValueInterface
{
    /**
     * @var float|null
     *
     * @Assert\NotBlank()
     */
    private $x;

    /**
     * @var float|null
     *
     * @Assert\NotBlank()
     */
    private $y;

// ...

As a result, if a user tries to publish the Point 2D with just one value, they will receive an error message.

Point 2D validation