ValidationConstraintMatchTrait.php in Lightning Media 8.3
Same filename and directory in other branches
Namespace
Drupal\lightning_mediaFile
src/ValidationConstraintMatchTrait.phpView source
<?php
namespace Drupal\lightning_media;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\media\MediaTypeInterface;
/**
* Implements InputMatchInterface for media types that use an embed code or URL.
*/
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;
}
}
Traits
Name![]() |
Description |
---|---|
ValidationConstraintMatchTrait | Implements InputMatchInterface for media types that use an embed code or URL. |