You are here

public function InstagramEmbedCodeConstraintValidator::validate in Media entity Instagram 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/InstagramEmbedCodeConstraintValidator.php \Drupal\media_entity_instagram\Plugin\Validation\Constraint\InstagramEmbedCodeConstraintValidator::validate()

File

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

Class

InstagramEmbedCodeConstraintValidator
Validates the InstagramEmbedCode constraint.

Namespace

Drupal\media_entity_instagram\Plugin\Validation\Constraint

Code

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