Hello Laminas Community!
I’ve got a simple fieldset that is successfully hydrating the expected entity, however, the validation in that fieldset’s getInputFilterSpecification
is being ignored.
The fieldset belongs to a Collection, which is added to the base form as such:
$this->add([
'name' => 'skill_rewards',
'type' => Collection::class,
'options' => [
'label' => 'Skill Rewards',
'allow_add' => true,
'target_element' => $this->skillRewardFieldset,
],
]);
The FieldSet’s construction is as follows:
class StepSkillRewardFieldset extends Fieldset implements InputFilterProviderInterface
{
private ObjectManager $objectManager;
public function __construct(ObjectManager $objectManager, ?string $name = null, array $options = [])
{
parent::__construct($name, $options);
$this->objectManager = $objectManager;
}
public function init()
{
$this->add([
'name' => 'skill',
'type' => ObjectSelect::class,
'options' => [
'property' => 'id',
'target_class' => Skill::class,
'object_manager' => $this->objectManager,
],
]);
$this->add([
'name' => 'points_rewarded',
'type' => Number::class,
'options' => [
'label' => 'Points Rewarded',
],
]);
}
/**
* @inheritDoc
*/
public function getInputFilterSpecification()
{
return [
'points_rewarded' => [
'required' => true,
'filters' => [
['name' => ToInt::class],
],
'validators' => [
[
'name' => GreaterThan::class,
'options' => [
'min' => 1,
'inclusive' => true,
],
],
],
],
'skill' => [
'required' => true,
'validators' => [
[
'name' => NotEmpty::class,
],
],
],
];
}
}
Despite this configuration, I am still able to push zero values for example into points_rewarded, and the system is happy to hydrate the object with a zero point value.
Am I missing a vital config option that would ask the Collection to apply the fieldset’s validation?
Thanks for the steer!