To do this, your custom class must be defined as a service, and you will access it from the controller using $form = $this->get('your.form.service'); instead of creating it directly.
When defining a service, make sure you enter the validation service:
your.form.service: class: Path\To\Your\Form arguments: [@validator]
Then you need to handle this in the method of building the form service:
protected $validator; function __construct(\Symfony\Component\Validator\Validator $validator) { $this->validator = $validator; }
source share