class InstagramEmbedCodeConstraintValidator in Media entity Instagram 8
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/InstagramEmbedCodeConstraintValidator.php \Drupal\media_entity_instagram\Plugin\Validation\Constraint\InstagramEmbedCodeConstraintValidator
Validates the InstagramEmbedCode constraint.
Hierarchy
- class \Drupal\media_entity_instagram\Plugin\Validation\Constraint\InstagramEmbedCodeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator uses EmbedCodeValueTrait
Expanded class hierarchy of InstagramEmbedCodeConstraintValidator
1 file declares its use of InstagramEmbedCodeConstraintValidator
- ConstraintsTest.php in tests/
src/ Unit/ ConstraintsTest.php
File
- src/
Plugin/ Validation/ Constraint/ InstagramEmbedCodeConstraintValidator.php, line 13
Namespace
Drupal\media_entity_instagram\Plugin\Validation\ConstraintView source
class InstagramEmbedCodeConstraintValidator extends ConstraintValidator {
use EmbedCodeValueTrait;
/**
* {@inheritdoc}
*/
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);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EmbedCodeValueTrait:: |
protected | function | Extracts the raw embed code from input which may or may not be wrapped. | |
InstagramEmbedCodeConstraintValidator:: |
public | function | Checks if the passed value is valid. |