You are here

public function VideoEmbedConstraintValidator::validate in Video Embed Field 8

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

File

src/Plugin/Validation/Constraint/VideoEmbedConstraintValidator.php, line 45

Class

VideoEmbedConstraintValidator
Validates the video embed providers.

Namespace

Drupal\video_embed_field\Plugin\Validation\Constraint

Code

public function validate($field, Constraint $constraint) {
  if (!isset($field->value)) {
    return NULL;
  }
  $allowed_providers = $field
    ->getFieldDefinition()
    ->getSetting('allowed_providers');
  $allowed_provider_definitions = $this->providerManager
    ->loadDefinitionsFromOptionList($allowed_providers);
  if (FALSE === $this->providerManager
    ->filterApplicableDefinitions($allowed_provider_definitions, $field->value)) {
    $this->context
      ->addViolation($constraint->message);
  }
}