trait FileInputExtensionMatchTrait in Lightning Media 8
Same name and namespace in other branches
- 8.4 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait
- 8.2 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait
- 8.3 src/FileInputExtensionMatchTrait.php \Drupal\lightning_media\FileInputExtensionMatchTrait
Implements InputMatchInterface for media types that use a file field.
Hierarchy
- trait \Drupal\lightning_media\FileInputExtensionMatchTrait
2 files declare their use of FileInputExtensionMatchTrait
File
- src/
FileInputExtensionMatchTrait.php, line 11
Namespace
Drupal\lightning_mediaView source
trait FileInputExtensionMatchTrait {
/**
* Returns the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager.
*/
private function entityTypeManager() {
return @($this->entityTypeManager ?: \Drupal::entityTypeManager());
}
/**
* Implements InputMatchInterface::appliesTo().
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileInputExtensionMatchTrait:: |
public | function | Implements InputMatchInterface::appliesTo(). | |
FileInputExtensionMatchTrait:: |
private | function | Returns the entity type manager. |