final class InstagramEmbedCodeConstraintValidator in Lightning Media 8.3
Same name and namespace in other branches
- 8.4 modules/lightning_media_instagram/src/Plugin/Validation/Constraint/InstagramEmbedCodeConstraintValidator.php \Drupal\lightning_media_instagram\Plugin\Validation\Constraint\InstagramEmbedCodeConstraintValidator
Validates the InstagramEmbedCode constraint.
@internal This is a totally internal part of Lightning Media Instagram and may be changed or removed in any way, at any time, without warning. External code should not use this class. If you need to use it or modify it, please copy it into your own project.
Hierarchy
- class \Drupal\lightning_media_instagram\Plugin\Validation\Constraint\InstagramEmbedCodeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of InstagramEmbedCodeConstraintValidator
File
- modules/
lightning_media_instagram/ src/ Plugin/ Validation/ Constraint/ InstagramEmbedCodeConstraintValidator.php, line 19
Namespace
Drupal\lightning_media_instagram\Plugin\Validation\ConstraintView source
final class InstagramEmbedCodeConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
$data = '';
if (is_string($value)) {
$data = $value;
}
elseif ($value instanceof FieldItemInterface) {
$class = get_class($value);
$property = $class::mainPropertyName();
if ($property) {
$data = $value->{$property};
}
}
if ($data) {
$matches = [];
foreach (Instagram::$validationRegexp as $pattern => $key) {
if (preg_match($pattern, $data, $item_matches)) {
$matches[] = $item_matches;
}
}
if (empty($matches)) {
$this->context
->addViolation($constraint->message);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InstagramEmbedCodeConstraintValidator:: |
public | function | Checks if the passed value is valid. |