public function FileInputExtensionMatchTrait::appliesTo in Lightning Media 8
Same name and namespace in other branches
- 8.4 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait::appliesTo()
- 8.2 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait::appliesTo()
- 8.3 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait::appliesTo()
Implements InputMatchInterface::appliesTo().
File
- src/
FileInputExtensionMatchTrait.php, line 26
Class
- FileInputExtensionMatchTrait
- Implements InputMatchInterface for media types that use a file field.
Namespace
Drupal\lightning_mediaCode
public function appliesTo($value, MediaTypeInterface $media_type) {
if (is_numeric($value)) {
$value = $this
->entityTypeManager()
->getStorage('file')
->load($value);
}
if ($value instanceof FileInterface && ($field = $this
->getSourceFieldDefinition($media_type))) {
$extension = pathinfo($value
->getFilename(), PATHINFO_EXTENSION);
$extension = strtolower($extension);
return in_array($extension, preg_split('/,?\\s+/', $field
->getSetting('file_extensions')));
}
return FALSE;
}