You are here

public function PlainTextFieldValidationRule::validate in Field Validation 8

Overrides FieldValidationRuleBase::validate

File

src/Plugin/FieldValidationRule/PlainTextFieldValidationRule.php, line 61

Class

PlainTextFieldValidationRule
PlainTextFieldValidationRule.

Namespace

Drupal\field_validation\Plugin\FieldValidationRule

Code

public function validate($params) {
  $value = isset($params['value']) ? $params['value'] : '';
  $rule = isset($params['rule']) ? $params['rule'] : null;
  $context = isset($params['context']) ? $params['context'] : null;
  if ($value != '' && strcmp($value, strip_tags($value))) {
    $context
      ->addViolation($rule
      ->getErrorMessage());
  }
}