You are here

class StateConstraintValidator in State Machine 8

Validates the State constraint.

Hierarchy

  • class \Drupal\state_machine\Plugin\Validation\Constraint\StateConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of StateConstraintValidator

See also

\Drupal\state_machine\Plugin\Field\FieldType\StateItemInterface::isValid()

File

src/Plugin/Validation/Constraint/StateConstraintValidator.php, line 13

Namespace

Drupal\state_machine\Plugin\Validation\Constraint
View source
class StateConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    if (!$value
      ->getEntity()
      ->isNew() && !$value
      ->isValid()) {
      $this->context
        ->addViolation($constraint->message, [
        '@state' => $value->value,
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StateConstraintValidator::validate public function Checks if the passed value is valid.