You are here

public function TweetEmbedCodeConstraintValidator::validate in Media entity Twitter 8

File

src/Plugin/Validation/Constraint/TweetEmbedCodeConstraintValidator.php, line 20

Class

TweetEmbedCodeConstraintValidator
Validates the TweetEmbedCode constraint.

Namespace

Drupal\media_entity_twitter\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  $value = $this
    ->getEmbedCode($value);
  if (!isset($value)) {
    return;
  }
  foreach (Twitter::$validationRegexp as $pattern => $key) {
    if (preg_match($pattern, $value)) {
      return;
    }
  }
  $this->context
    ->addViolation($constraint->message);
}