You are here

public function WorkflowFieldConstraintValidator::validate in Workflow 8

File

src/Plugin/Validation/Constraint/WorkflowFieldConstraintValidator.php, line 53

Class

WorkflowFieldConstraintValidator
Validates the CommentName constraint.

Namespace

Drupal\workflow\Plugin\Validation\Constraint

Code

public function validate($entity, Constraint $constraint) {

  // Workflow field name on CommentForm has special requirements.

  /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
  $field_storage = $entity
    ->getFieldDefinition()
    ->getFieldStorageDefinition();
  if (!$this
    ->isValidFieldname($field_storage)) {
    $this->context
      ->buildViolation($constraint->messageFieldname)
      ->atPath('fieldnameOnComment')
      ->addViolation();
  }
}