trait ValidationConstraintMatchTrait in Lightning Media 8
Same name and namespace in other branches
- 8.4 src/ValidationConstraintMatchTrait.php \Drupal\lightning_media\ValidationConstraintMatchTrait
- 8.2 src/ValidationConstraintMatchTrait.php \Drupal\lightning_media\ValidationConstraintMatchTrait
- 8.3 src/ValidationConstraintMatchTrait.php \Drupal\lightning_media\ValidationConstraintMatchTrait
Implements InputMatchInterface for media types that use an embed code or URL.
Hierarchy
- trait \Drupal\lightning_media\ValidationConstraintMatchTrait
2 files declare their use of ValidationConstraintMatchTrait
- Instagram.php in modules/
lightning_media_instagram/ src/ Plugin/ media/ Source/ Instagram.php - Twitter.php in modules/
lightning_media_twitter/ src/ Plugin/ media/ Source/ Twitter.php
File
- src/
ValidationConstraintMatchTrait.php, line 11
Namespace
Drupal\lightning_mediaView source
trait ValidationConstraintMatchTrait {
/**
* Returns the typed data manager.
*
* @return \Drupal\Core\TypedData\TypedDataManagerInterface
* The typed data manager.
*/
private function typedDataManager() {
return @($this->typedDataManager ?: \Drupal::typedDataManager());
}
/**
* Implements InputMatchInterface::appliesTo().
*/
public function appliesTo($value, MediaTypeInterface $media_type) {
$plugin_definition = $this
->getPluginDefinition();
$definition = $this
->typedDataManager()
->createDataDefinition('string')
->addConstraint($plugin_definition['input_match']['constraint']);
$data = StringData::createInstance($definition);
$data
->setValue($value);
return $data
->validate()
->count() === 0;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ValidationConstraintMatchTrait:: |
public | function | Implements InputMatchInterface::appliesTo(). | |
ValidationConstraintMatchTrait:: |
private | function | Returns the typed data manager. |