class ClassResolverConstraint

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ClassResolverConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ClassResolverConstraint

Checks if a method on a service or instantiated object returns true.

For example to call the method 'isValidScheme' on the service 'stream_wrapper_manager', use: ['stream_wrapper_manager', 'isValidScheme']. It is also possible to use a class if it implements ContainerInjectionInterface. It will use the ClassResolver to resolve the class and return an instance. Then it will call the configured method on that instance.

The called method should return TRUE when the result is valid. All other values will be considered as invalid.

Attributes

#[Constraint(id: 'ClassResolver', label: new TranslatableMarkup('Call a method on a service', [], [ 'context' => 'Validation', ]), type: FALSE)]

Hierarchy

  • class \Drupal\Core\Validation\Plugin\Validation\Constraint\ClassResolverConstraint extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of ClassResolverConstraint

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ClassResolverConstraint.php, line 24

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint
View source
class ClassResolverConstraint extends SymfonyConstraint {
  public function __construct(public string $classOrService, public string $method, public string $message = "Calling '@method' method with value '@value' on '@classOrService' evaluated as invalid.", ?array $groups = NULL, mixed $payload = NULL) {
    parent::__construct(groups: $groups, payload: $payload);
  }

}

Members

Title Sort descending Modifiers Object type Summary
ClassResolverConstraint::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.