3 namespace Drupal\video_embed_field\Plugin\Validation\Constraint;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\video_embed_field\ProviderManagerInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\Validator\Constraint;
9 use Symfony\Component\Validator\ConstraintValidator;
12 * Validates the video embed providers.
14 class VideoEmbedConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
17 * Video embed provider manager service.
19 * @var \Drupal\video_embed_field\ProviderManagerInterface
21 protected $providerManager;
24 * Create an instance of the validator.
26 * @param \Drupal\video_embed_field\ProviderManagerInterface $provider_manager
27 * The provider manager service.
29 public function __construct(ProviderManagerInterface $provider_manager) {
30 $this->providerManager = $provider_manager;
36 public static function create(ContainerInterface $container) {
38 $container->get('video_embed_field.provider_manager')
45 public function validate($field, Constraint $constraint) {
46 if (!isset($field->value)) {
50 $allowed_providers = $field->getFieldDefinition()->getSetting('allowed_providers');
51 $allowed_provider_definitions = $this->providerManager->loadDefinitionsFromOptionList($allowed_providers);
53 if (FALSE === $this->providerManager->filterApplicableDefinitions($allowed_provider_definitions, $field->value)) {
54 $this->context->addViolation($constraint->message);