I have a custom form control implementing Nette\Forms\Control interface.
I want to add a common rule to check if that control is filled. Sadly, the default implementation delegates to the static Validator class that requires a BaseControl subtype.
| publicstaticfunctionvalidateFilled(Controls\BaseControl$control): bool |
I worked around this by providing custom rules that override the filled check:
class CustomControlRules extends Rules
{
publicstaticfunctionvalidateRule(Rule$rule): bool
{
if ($rule->validator === Form::Filled) {
$control = $rule->control;
if (!$controlinstanceof \MyCustomImplementation) {
thrownewInvalidStateException();
}
return$control->isFilled();
} else {
returnparent::validateRule($rule);
}
}
}But, this is getting forbidden by the recent (Forms 3.2) changes that are making the Rules class final.
The simple solution is to remove the final once again, but since I got to report this, I'd ask you to consider some proper LSP solution -> ideally moving the required methods to the interface.
I have a custom form control implementing
Nette\Forms\Controlinterface.I want to add a common rule to check if that control is filled. Sadly, the default implementation delegates to the static Validator class that requires a
BaseControlsubtype.forms/src/Forms/Validator.php
Line 162 in fcfc86c
I worked around this by providing custom rules that override the filled check:
But, this is getting forbidden by the recent (Forms 3.2) changes that are making the Rules class final.
The simple solution is to remove the final once again, but since I got to report this, I'd ask you to consider some proper LSP solution -> ideally moving the required methods to the interface.