class VideoEmbedConstraintValidator in Video Embed Field 8
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/VideoEmbedConstraintValidator.php \Drupal\video_embed_field\Plugin\Validation\Constraint\VideoEmbedConstraintValidator
Validates the video embed providers.
Hierarchy
- class \Drupal\video_embed_field\Plugin\Validation\Constraint\VideoEmbedConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of VideoEmbedConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ VideoEmbedConstraintValidator.php, line 14
Namespace
Drupal\video_embed_field\Plugin\Validation\ConstraintView source
class VideoEmbedConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* Video embed provider manager service.
*
* @var \Drupal\video_embed_field\ProviderManagerInterface
*/
protected $providerManager;
/**
* Create an instance of the validator.
*
* @param \Drupal\video_embed_field\ProviderManagerInterface $provider_manager
* The provider manager service.
*/
public function __construct(ProviderManagerInterface $provider_manager) {
$this->providerManager = $provider_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('video_embed_field.provider_manager'));
}
/**
* {@inheritdoc}
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
VideoEmbedConstraintValidator:: |
protected | property | Video embed provider manager service. | |
VideoEmbedConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
VideoEmbedConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
VideoEmbedConstraintValidator:: |
public | function | Create an instance of the validator. |