How can I add custom validators with parameters in API Tools GUI?
I wrote a custom validator + factory.
I have some setters+getters there.
How can I configure this validator the way it would:
- show up in the list of available validators in the GUI (I'm adding a factory to
validators.factorieskey in themodule.config.php - allow the user to choose parameters (eg.
maxlen,minlenetc.). Now it shows only one option available:breakchainonfailure
Similar to the StringLength validator:

My factory:
<?php
namespace My\Validator\DoctrineConnected\Factory;
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;
class ExistsValidatorFactory implements AbstractFactoryInterface {
/**
* Create an object
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return object
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) {
$entityManger = $container->get('doctrine.entitymanger.orm_default');
return new $requestedName($entityManger);
}
public function canCreate(ContainerInterface $container, $requestedName)
{
return class_exists($requestedName);
}
}
You have to define the validator metadata in your
module.config.phpof your module.For the defined options in the validator metadata you can set default values in the validator factory. Please avoid using the
Interop\Containerpackage and use thePsr\Containerpackage.The options you 've defined in the validator config will be passed as
$optionsparameter to the validator factory. Thebreakchainonfailureis a default option for validators in the laminas framework.