Add support for Symfony Callback Constraint
g089h515r806 created an issue. See original summary.
Issue #3381360 by g089h515r806: Add support for Symfony Callback...
test case: add a Callback constraint to field_test, set callback to "\Drupal\mymodule\MyValidator::validate", save it.
here is the code :
namespace Drupal\mymodule; use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * My validator callback. */ class MyValidator { /** * {@inheritdoc} */ public static function validate(mixed $items, ExecutionContextInterface $context, mixed $payload): void{ if (!$item = $items->first()) { return; } if(mb_strlen($item->value) < 3){ $context->addViolation("The length is too low."); } } }
if populate field_test "abc", no error message.
if populate field_test "ab", get an error message.
Automatically closed - issue fixed for 2 weeks with no activity.
Comments
Comment #3
g089h515r806 commentedtest case:
add a Callback constraint to field_test, set callback to "\Drupal\mymodule\MyValidator::validate", save it.
here is the code :
if populate field_test "abc", no error message.
if populate field_test "ab", get an error message.
Comment #4
g089h515r806 commented