- Issue created by @g089h515r806
-
g089h515r806 →
committed f8721a50 on 3.0.x
Issue #3381360 by g089h515r806: Add support for Symfony Callback...
-
g089h515r806 →
committed f8721a50 on 3.0.x
- 🇨🇳China g089h515r806
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.
- Status changed to Fixed
over 1 year ago 1:35pm 19 August 2023 Automatically closed - issue fixed for 2 weeks with no activity.